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}")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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}")

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY