Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

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

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education