Concept explainers
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}")
Step by stepSolved in 2 steps with 1 images
- Explain how many times the following loop will be executed. LXI B,0007H LOOP: DCX B MOV A,B ORA C JNZ LOOParrow_forwardPEN AND PAPER FLOWCHART. Hand write the correct pseudocode using pen and paper. DEBUG03-03 // This pseudocode is intended to display// employee net pay values. All employees have a standard// $45 deduction from their checks.// If an employee does not earn enough to cover the deduction,// an error message is displayed.// This example is modularized.start Declarations string name string EOFNAME = ZZZZ while name not equal to EOFNAME housekeeping() endwhile while name not equal to EOFNAME mainLoop() endwhile while name not equal to EOFNAME finish() endwhilestop housekeeping() output "Enter first name or ", EOFNAME, " to quit "return mainLoop() Declarations num hours num rate num DEDUCTION = 45 num net output "Enter hours worked for ", name input hours output "Enter hourly rate for ", name input rate gross = hours * rate net = gross - DEDUCTION if net > 0 then output "Net pay for ", name, " is ", net…arrow_forwardUnavailable Expressions For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a float, strs in quotes). Expression Value 1 2 3 4 5 5 // 2 + 9.0 / 2.0 - 21.25 29 & 2 & 5 + 34 % 3 8 + 6 -2 +4 +(2+5) > 5 31 // 2 / 10.0 + 10 / (5/ 2.0) (1 != 2) != (2 != 3) Desktoparrow_forward
- Programming language is C#arrow_forwardC++ Coding: Nested Loops Create a constant DIM. Set DIM to 7, and use a nested loop to display the following square matrix output. Output Example: - - - X - - -- - - X - - -- - - X - - -X X X O X X X- - - X - - -- - - X - - -- - - X - - -arrow_forwardTrue or False When a variable is declared in the initialization expression of a for loop, the scope of the variable is limited to the loop.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education