Zybooks 4.18 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.
I want to know if there's anything I can use in place of change.remove() to remove that variable from "change." I know that change.remove() doesn't work but put it there to show what it is that I want to do. I'm taking my first Computer Science class right now, so keep in mind that there are a lot of things I might not have learned yet. I know that this problem has been solved before on here before, but I'm trying to write a code with what I have learned so far. Is there any way that I could do this problem using what I have and only fixing a few elements? This is what I have right now:
x=int(input())
if x<=0:
print('No change')
else:
num_of_dollars = x//100
x = x-num_of_dollars*100
num_of_quarters = x//25
x = x-num_of_quarters*25
num_of_dimes = x//10
x = x-num_of_dimes*10
num_of_nickels = x//5
x = x-num_of_nickels*5
num_of_pennies = x//1
change = dollars+'\n'+quarters+'\n'+dimes+'\n'+nickels+'\n'+pennies
if num_of_dollars>1:
dollars = str(num_of_dollars)+' Dollars'
elif num_of_dollars==1:
dollars = str(num_of_dollars)+' Dollar'
elif num_of_dollars==0:
change.remove(dollars)
if num_of_quarters>1:
quarters = str(num_of_quarters)+' Quarters'
elif num_of_quarters==1:
quarters = str(num_of_quarters)+' Quarter'
elif num_of_quarters==0:
change.remove(quarters)
if num_of_dimes>1:
dimes = str(num_of_dimes)+' Dimes'
elif num_of_dimes==1:
dimes = str(num_of_dimes)+' Dime'
elif num_of_dimes==0:
change.remove(dimes)
if num_of_nickels>1:
nickels = str(num_of_nickels)+' Nickels'
elif num_of_nickels==1:
nickels = str(num_of_nickels)+' Nickel'
elif num_of_nickels==0:
change.remove(nickels)
if num_of_pennies>1:
pennies = str(num_of_pennies)+' Pennies'
elif num_of_pennies==1:
pennies = str(num_of_pennies)+' Penny'
elif num_of_pennies==0:
change.remove(pennies)
print(change)