In: Computer Science
Write a program in pyton 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
Can you provide the full code from begging to end. Thanks, will give you a thumps up!
if __name__ == '__main__': user_int = int(input()) if user_int <= 0: print("No Change") else: dollars = user_int // 100 user_int %= 100 quarters = user_int // 25 user_int %= 25 dimes = user_int // 10 user_int %= 10 nickels = user_int // 5 user_int %= 5 pennies = user_int if dollars > 1: print(dollars, 'Dollars') elif dollars == 1: print(dollars, 'Dollar') if quarters > 1: print(quarters, 'Quarters') elif quarters == 1: print(quarters, 'Quarter') if dimes > 1: print(dimes, 'Dimes') elif dimes == 1: print(dimes, 'Dime') if nickels > 1: print(nickels, 'Nickels') elif nickels == 1: print(nickels, 'Nickel') if pennies > 1: print(pennies, 'Pennies') elif pennies == 1: print(pennies, 'Penny')