Hello, I am trying to self learn python from a book called the coders apprentice. I really like the book and I am learning from it. I encountered an exercise that asks you to determine how many dollars, quarters, dimes, nickels and pennies of change you will have in a specific amount for example 1156 cents. The code for the program is here
but with this program I dont see how it works and tried to understand how the compound operators work and I am stuck. Can someone please explain to me how the cents obtains its new value from the calculation on the right?
Thank you very much
CENTS_IN_DOLLAR = 100 CENTS_IN_QUARTER = 25 CENTS_IN_DIME = 10 CENTS_IN_NICKEL = 5 amount = 1156 cents = amount dollars = int( cents / CENTS_IN_DOLLAR ) cents -= dollars * CENTS_IN_DOLLAR quarters = int( cents / CENTS_IN_QUARTER ) cents -= quarters * CENTS_IN_QUARTER dimes = int( cents / CENTS_IN_DIME ) cents -= dimes * CENTS_IN_DIME nickels = int( cents / CENTS_IN_NICKEL ) cents -= nickels * CENTS_IN_NICKEL cents = int( cents ) print( amount / CENTS_IN_DOLLAR, "consists of:" ) print( "Dollars:", dollars ) print( "Quarters:", quarters ) print( "Dimes:", dimes ) print( "Nickels:", nickels ) print( "Pennies:", cents )I understand when something is x = x+5
but with this program I dont see how it works and tried to understand how the compound operators work and I am stuck. Can someone please explain to me how the cents obtains its new value from the calculation on the right?
Thank you very much