So I'm working on a school project with the following prompt:
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:
45
The output is:
1 Quarter 2 Dimes
I've traveling down a rabbit hole trying to get this to work. I have the math right for the computation part, but then I decided to store the information inside of a list. Trying to remove all of the values not equal to zero led me to list comprehension, but now, I'm stuck on how to write print code that allows the output to look like it should above. Any ideas?
Here is my code currently:
change = int(input())
dollars = change // 100
quarters = change % 100 // 25
dimes = change % 100 % 25 // 10
nickles = change % 100 % 25 % 10 // 5
pennies = change % 100 % 25 % 10 % 5 // 1
list = [dollars, quarters, dimes, nickles, pennies]
no_zero_in_list = [x for x in list if x != 0]
print(*no_zero_in_list)