Provide description on how to use the code. Code is located below: # initialize a flag variable with 0 flag = 0 # loop will execute till flag is 0 in the sense loop will execute code while flag == 0 :...



Provide description on how to use the code.



Code is located below:


# initialize a flag variable with 0
flag = 0 # loop will execute till flag is 0 in the sense loop will execute code
while flag == 0 : #until amount is greater then cost
cost = float(input("Enter the cost: ")) # take input cost and convert to floating data type
amount = float(input("Enter the amount given(should be greater than cost): ")) # take input
if amount < cost="">
print("Amount should be greater than cost.") #print statement saying enter Amount that
else:
flag = 1 # when amount entered by user greater then cost flag is set to 1 and while loop will not execute




change = amount-cost #stored difference between amount and cost to change variable
print(f"The change to be given is ${change}") #print the value of change variable


twenty=0 #intializing all possible coin/ notes to 0
ten=0
five=0
single=0
quarter=0
dime=0
nickel=0
penny=0


while change>=20 : #loop will execute until change become less then 20. this loop execute for change>20
twenty+=1 #incrementing twenty until change is greater than or equal to 20
change-=20 #decrementing 20 from change


while change>=10 : # loop will execute until change is less then 10. this loop will execute for change(19.9999.. to 10)
ten+=1#doing the above operation for all possible dollar bills
change-=10 # decreasing change values by 10


while change>=5:#loop will execute until change will become less then 5. c change(9.999.. to5)
five+=1
change-=5


while change>=1:#loop will execute for until change become less then 1.this loop will execute for change(4.999... to 1)
single+=1
change-=1


while change>=0.25:#loop will execute for until change become less then 0.25. this loop will execute for change(0.99..to 0.25). similarly for other while loop
quarter+=1
change-=0.25


while change>=0.10:
dime+=1
change-=0.10


while change>=0.05:#Checking with 0 to counter precision penny+=1
nickel+=1
change-=0.05


while change>=0: #Checking with 0 to counter precision
penny+=1
change-=0.01


#Displaying the results
#printing all new values for different coin/notes/currency are got as change
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}")

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here