n = int(input('Enter the amount: '))
# converting the cents into dollars and cents
dollars = n // 100
cent = n % 100
# printing the dollars and cents
print('The Change for %d dollars and %d cent' % (dollars, cent))
# variables to store the number of various denomiations of money
hundred_dollars = 0
fity_dollars = 0
twenty_dollars = 0
ten_dollars = 0
five_dollars = 0
one_dollars = 0
quarters =0
dime = 0
nickel = 0
pennies = 0
# converting the cents into hundred dollar
hundred_dollars, dollars = divmod(n, 10000)
# convering the cents into fifty dollar
fifty_dollars, cents = divmod(n, 5000)
# converting the cents into twenty dollar
twenty_dollars, cents = divmod(n, 2000)
# converting the cents into ten dollar
ten_dollars, cents = divmod(cents, 1000)
# converting the cents into five dollar
five_dollars, cents = divmod(cents, 500)
# converting the cents into one dollar
one_dollars, cents = divmod(cents, 100)
# converting the cents into quarters
quarters, cents = divmod(cents, 25)
# converting the cents into dime
dime, cents = divmod(cents, 10)
# converting the cents into pennies and nickel
nickel, pennies = divmod(cents, 5)
# displaying the various denominations
print('%dx Hundred Dollars bills' % hundred_dollars)
print('%dx Fifty Dollars bills' % fifty_dollars)
print('%dx Twenty Dollars bills' % twenty_dollars)
print('%dx Ten Dollars bills' % ten_dollars)
print('%dx Five Dollars bills' % five_dollars)
print('%dx one Dollars bills' % one_dollars)
print('%dx Quarters' % quarters)
print('%dx Dime' % dime)
print('%dx Nickel' % nickel)
print('%dx Pennies' % pennies)
if i input the value of 10000 cents it outputs with 1 hundred and 5 20s i need it to only show 1 hundred can someone please help im new to python, this also happens when you input 5000 to get 1 fifty. i know its something wrong with the divmod and that i need to subtract something so that im not working with the original amount but i dont understand how i am supposed to do so
CodePudding user response:
The problem isn't with divmod. The problem here is that after checking the number of hundred dollar notes, it checks the number of fifty dollar notes within the same amount of cash and the same with all other note types. What you need to do is only get the change in other note types of your leftover dollars. So something like so may help:
n = int(input('Enter the amount: '))
# converting the cents into dollars and cents
dollars = n // 100
cent = n % 100
# printing the dollars and cents
print('The Change for %d dollars and %d cent' % (dollars, cent))
# converting the cents into hundred dollar
hundred_dollars, dollars = divmod(dollars, 100)
# convering the cents into fifty dollar
fifty_dollars, dollars = divmod(dollars, 50)
# converting the cents into twenty dollar
twenty_dollars, dollars = divmod(dollars, 20)
# converting the cents into ten dollar
ten_dollars, dollars = divmod(dollars, 10)
# converting the cents into five dollar
five_dollars, one_dollars = divmod(dollars, 5)
# converting the cents into quarters
quarters, cents = divmod(cents, 25)
# converting the cents into dime
dime, cents = divmod(cents, 10)
# converting the cents into pennies and nickel
nickel, pennies = divmod(cents, 5)
# displaying the various denominations
print('%dx Hundred Dollars bills' % hundred_dollars)
print('%dx Fifty Dollars bills' % fifty_dollars)
print('%dx Twenty Dollars bills' % twenty_dollars)
print('%dx Ten Dollars bills' % ten_dollars)
print('%dx Five Dollars bills' % five_dollars)
print('%dx one Dollars bills' % one_dollars)
print('%dx Quarters' % quarters)
print('%dx Dime' % dime)
print('%dx Nickel' % nickel)
print('%dx Pennies' % pennies)
CodePudding user response:
Please share the divmod function so as to justify whats happening wrong in the function, so the mistake is identifiable!