Stuck in LAB: Exact Change [closed]

Does anyone have any idea how to solve ZyBooks LAB Exact Change ? I got 6 out of 10 point but have a bug in the nickel area. This is exactly how I have it

cents = int(input())

if cents == 0:
    print("No change")

num_dollars = cents // 100
cents_left = cents % 100

num_quarters = cents_left // 25
cents_left = cents_left % 25

num_dimes = cents_left // 10
cent_left = cents_left % 10

num_nickels = cents_left // 5
cents_left = cents_left % 5

num_pennies = cents_left // 1
cents_left = cents_left % 1

if num_dollars == 1:
    print(num_dollars, "Dollar")
elif num_dollars > 0:
    print(num_dollars, "Dollars")

if num_quarters == 1:
    print(num_quarters, "Quarter")
elif num_quarters > 0:
    print(num_quarters, "Quarters")

if num_dimes == 1:
    print(num_dimes, "Dime")
elif num_dimes > 0:
    print(num_dimes, "Dimes")

if num_nickels == 1:
    print(num_nickels, "Nickel")
elif num_nickels > 0:
    print(num_nickels, "Nickels")

if num_pennies == 1:
    print(num_pennies, "Penny")
elif num_pennies > 0:
    print(num_pennies, "Pennies")

I tried many ways to make my program work but I cannot.

  • 1

    When you calculate the dimes, you mistakenly assign cent_left instead of cents_left.

    – 

  • Your math is incorrect in all cases. After calculating the number of dollars, the values of cents_left is not cents % 100; it’s cents - num_dollars * 100. You have the same issue for every calculation.

    – 

  • @larsks Huh? How is that different? And how did they get 6 out of 10 right with such a fundamental bug?

    – 

  • Thank you John Gordon, I did not see that one earlier been at it all night. And larsks I did try that earlier I kept getting many errors.

    – 

  • the math is good but I get errors in the nickel area

    – 

Leave a Comment