Can you annotate this code flag = 0 while flag == 0 : cost = float(input("Enter the cost: ")) amount = float(input("Enter the amount given(should be greater than cost): ")) if amount < cost : print("Amount should be greater than cost.") else: flag = 1 change = amount-cost print(f"The change to be given is ${change}") twenty=0 ten=0 five=0 single=0 quarter=0 dime=0 nickel=0 penny=0 while change>=20 : twenty+=1 #incrementing twenty until change is greater than or equal to 20 change-=20 #decrementing 20 from change while change>=10 : ten+=1#doing the above operation for all possible dollar bills change-=10 while change>=5: five+=1 change-=5 while change>=1: single+=1 change-=1 while change>=0.25: quarter+=1 change-=0.25 while change>=0.10: dime+=1 change-=0.10 while change>=0.05: nickel+=1 change-=0.05 while change>=0: #Checking with 0 to counter precision penny+=1 change-=0.01 #Displaying the results print(f"For that you require the following:") print(f"Twenty dollar bills: {twenty}") print(f"Ten dollar bills: {ten}") print(f"Five dollar bills: {five}") print(f"Single dollar bills: {single}") print(f"Quarter dollar bills: {quarter}") print(f"Dime dollar bills: {dime}") print(f"Nickle dollar bills: {nickel}") print(f"Penny dollar bills: {penny}")
Can you annotate this code
flag = 0
while flag == 0 :
cost = float(input("Enter the cost: "))
amount = float(input("Enter the amount given(should be greater than cost): "))
if amount < cost :
print("Amount should be greater than cost.")
else:
flag = 1
change = amount-cost
print(f"The change to be given is ${change}")
twenty=0
ten=0
five=0
single=0
quarter=0
dime=0
nickel=0
penny=0
while change>=20 :
twenty+=1 #incrementing twenty until change is greater than or equal to 20
change-=20 #decrementing 20 from change
while change>=10 :
ten+=1#doing the above operation for all possible dollar bills
change-=10
while change>=5:
five+=1
change-=5
while change>=1:
single+=1
change-=1
while change>=0.25:
quarter+=1
change-=0.25
while change>=0.10:
dime+=1
change-=0.10
while change>=0.05:
nickel+=1
change-=0.05
while change>=0: #Checking with 0 to counter precision
penny+=1
change-=0.01
#Displaying the results
print(f"For that you require the following:")
print(f"Twenty dollar bills: {twenty}")
print(f"Ten dollar bills: {ten}")
print(f"Five dollar bills: {five}")
print(f"Single dollar bills: {single}")
print(f"Quarter dollar bills: {quarter}")
print(f"Dime dollar bills: {dime}")
print(f"Nickle dollar bills: {nickel}")
print(f"Penny dollar bills: {penny}")
Step by step
Solved in 2 steps