
Can you provide a description outlining which method chosen to write the python code and a description of how the program works and how to use it. The code is below. I also attach a flowchart.
# 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}")


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- In C#arrow_forwardEven though the EXIT clause can be used in any type of loop, it is considered good form to use the EXIT clause only in basic loops. Answers: Yes Noarrow_forwardIs it real or not? A variable's scope is limited to the for loop when it is specified in the initialization phrase.arrow_forward
- Computer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forwardprogram must include a processing loop that allows multiple sets of data to be processed and the program should be terminated when there is no more data to process Develop a program in python that allows the user to enter a start value of 1 to 4, a stop value of 5 to 12 and a multiplier of 2 to 8. The program must display a multiplication table with results using these values. For example, if the user enters a start value of 3, a stop value of 7 and a multiplier value of 3, the table should be displayed as follows: Multiplication Table 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 Run the program with the following values: Start Stop Multiplier 2 10 4 4 12 6arrow_forwardDesign a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Modularize the program. Present clear formatted code with comments. I need this coded in pseudocode, please.arrow_forward
- QUESTION 9 Consider the steps you would take to write code that prints the output (below) meeting these criteria: • Use a while loop. • Declare a loop-control variable called noofSteps that is to be tested against 12. *****Output***** Step 1 Step 2 Step 3 <== Not part of actual output. .. Step 12 Choose the correct response to answer each question: 1) What is the means of stopping the while loop? 2) What is this while loop doing? 3) How is the loop-control variable modified? 4) Rather than testing noofSteps against 12, another valid test expression isarrow_forwardIs it real or not? A variable's scope is limited to the for loop when it is specified in the initialization phrase.arrow_forward•Get 10 numbers from user using loop. Find which number is a. positive b. negative C. zero d. Odd e. Even . Write Algorithm as well as Design a flowchart for the above problem.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





