Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

3.

27 LAB: Exact change


Write a 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

amount = int(input())

if amount<=0:

print("No change")

else:

dollar = int(amount/100)

amount = amount % 100


quarter = int(amount/25)

amount = amount % 25

dime = int(amount/10)

amount = amount % 10

nickel = int(amount/5)

penny = amount % 5

if dollar >= 1:

if dollar == 1:

print(str(dollar)+" Dollar")

else:

print(str(dollar)+" Dollars")

if quarter >= 1:

if quarter == 1:

print(str(quarter)+" Quarter")

else:
print(str(quarter)+" Quarters")

if dime >= 1:

if dime == 1:

print(str(dime)+" Dime")

else:

print(str(dime)+" Dimes")

if nickel >= 1:

if nickel == 1:

print(str(nickel)+" Nickel")

else:

print(str(nickel)+" Nickels")

if penny >= 1:

if penny == 1:

print(str(penny)+" Penny")
else:

print(str(penny)+" Pennies")

You might also like