Question: I cannot figure out why my code doesn't return anything, so I started indenting more and I think I messed it up worse. Can someone
I cannot figure out why my code doesn't return anything, so I started indenting more and I think I messed it up worse. Can someone help me sort this?
SCENARIO:
Havea program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.
Ex: If the input is:
0
(or less than 0), the output is:
No change Ex: If the input is:
45
the output is:
1 Quarter 2 Dimes
MY CODE:
def changeFunction(amount):
if amount >= 100:
dollars = amount//100
if dollars > 1:
print(dollars, ' Dollars')
else:
print(dollars, ' Dollar')
elif amount >= 25:
quarters = amount // 25
if quarters > 1:
print(quarters, ' Quarters')
else:
print(quarters, ' Quarter')
elif amount >= 10:
dimes = amount // 10
if dimes > 1:
print(dimes, ' Dimes')
else:
print(dimes, ' Dime')
elif amount >= 5:
nickels = amount // 5
if nickels > 1:
print(nickels, ' Nickels')
else:
print(nickels, ' Nickel')
elif amount >=1:
pennies = amount // 1
if pennies > 1:
print(pennies, ' Pennies')
else:
print(pennies, ' Penny')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
