0

So im having trouble with this Activity i've got it mostl figured out but whenever it is given an input of 45. the output is only 2 Dimes. and nothing else. but 46 and 44 and everything else gives me the perfect output. whats wrong?

pennies=int(input())
dollars = 0
quarters = 0
dimes = 0
nickels = 0


if pennies == 0:
    print('No change')

if pennies > 100:
    dollars = int(pennies/100) 
    pennies = (pennies%100)

if pennies > 25:
    quarters = (pennies//25)
    pennies = (pennies%25)

if pennies > 10:
    dimes = int(pennies/10)
    pennies = pennies%10

if pennies > 5:
    nickels = int(pennies/5)
    pennies = (pennies%5)

if (dollars > 1):
    print ( dollars,'Dollars')
elif (pennies > 0) and (dollars == 1):
    print (dollars, 'Dollar')

if (quarters > 1):
    print ( quarters,'Quarters')
elif (pennies > 0) and (quarters == 1):
    print (quarters, 'Quarter')
    
if (dimes > 1):
    print ( dimes,'Dimes')
elif (pennies > 0) and (dimes == 1):
    print (dimes, 'Dime')

if (nickels > 1):
    print ( nickels,'Nickels')
elif (pennies > 0) and (nickels == 1):
    print (nickels, 'Nickel')
    
if (pennies > 1):
    print ( pennies,'Pennies')
elif (pennies > 0) and (pennies == 1):
    print (pennies, 'Penny')
    
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 1
    Because the pennies value keep changing condition by condition itself. For example if you give penny as 45, it initially satisfy `>25` condition and penny value is changes as per the condition. The changed value of penny again move to the next condition of `>10`. If that satisfies again it start to change. Your condition is seems meaningless in that case. If possible please provide the logic that you need. Thank you. – Berlin Benilo Jul 14 '22 at 17:50
  • Welcome to Stack Overflow! Please take the [tour] and read [How to ask and answer homework questions](https://meta.stackoverflow.com/q/334822/4518341). What do you need help with exactly? I mean, have you done any work to narrow down the problem, like debugging to see how the variables change? Check out [How to step through Python code to help debug issues?](/q/4929251/4518341) Some of the solutions there might be overwhelming for a newbie, but you might like Python Tutor or PyCharm or VSCode. For more tips, see [ask], which covers how to write a good title. – wjandrea Jul 14 '22 at 18:01
  • nvm it was answered. I forgot to have all the variables be >= not just> – Rylan Champion Jul 14 '22 at 18:37

0 Answers0