Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These are test that should work! Please show all work!!! Your program must meet the following specifications: . At program start, assume a stock of

image text in transcribed

image text in transcribed

These are test that should work! Please show all work!!!

image text in transcribed

image text in transcribed

Your program must meet the following specifications: . At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repcatedly prompt the user for a price in the form xx.xx, where x denotes a digit, or to enter 'q to quit. When a price is entered: a. 3. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q'). Prompt for the number of dollars in payment. If the payment is insufficient, print an error message and reprompt for payment. Next determine the coins to be dispensed as change. This calculation will depend on the amount to be dispensed and also on the number of coins left in the stock. For example, the least number of coins needed to make change of $1.30 is 6: 5 quarters and 1 nickel. But if there are only 3 quarters, 3 dimes, and 10 nickels left in the stock, then the least number is 11: 3 quarters, 3 dimes, and 5 nickels. b. e d. Print the numbers of the coins to be dispensed as change and their denominations. (Omit a denomination if no coins of that denomination will be dispensed.) e In case exact payment is made, print a message such as "No change." f If the change cannot be made up with the coins remaining, print an error message and halt the program Notes and Hints: . To clarify the project specifications, sample output is appended to the end of this document. 2. Items 1-6 of the Coding Standard will be enforced for this project 3. we providea proj 02 . py program for you to start with. It hasa simple while loop (notice how input is prompted before the loop and at the bottom of the loop. More importantly it includes the in atr.aplit("." method call from the Strings chapter coming up next. That call splits the input instr at the period ( " returning the two strings that were split by the period. You will need to convert those strings to numbers (ints). Floating point numbers can be difficult to work with due to imprecision. To avoid imprecision do your calculations in cents, i.e. as type int. For example, $1.15 is the same as 115 cents. To see the problem, try evaluating 1.15 100 in the Python shell and compare that to evaluating round (1.15 100) 4. . There are many ways to calculate the maximum number of quarters to make change using the greedy algorithm. a. One is with a while loop where you keep subtracting 25 from the amount of change due and increment the number of quarters. End the loop when there are less than 25 cents due or you are out of quarters. After determining quarters you can determine dimes in the same way, e.g, using 10 instead of 25. Work your way down through the other coins. Alternatively, use the quotient (n operation for integers for finding the numbers of cach coin. For example, 195/25 is 7 the most mumber of quarters in 195 cents. However, be careful: if the stock has fewer than 7 quarters left, you will only be able to dispense the number left in the stok. For example, if there are only 6 quarters left, then you can dispense only 6 quarters and must use dimes and nickels to make up any remaining change. b. 6. When we learn about formating strings, we can more casily and elegantly print monetary amounts. For now, just use the Python print(..) command with appropriate string and/or integer arguments to print the number of dollars and the number of cents You do not need to check for any input errors other than those mentioned in this description. You may not use advanced data structures such as lists, dictionaries, sets or classes in solving this problem. 7. 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago

Question

5. Arranging for the training facility and room.

Answered: 1 week ago

Question

1. Discuss the five types of learner outcomes.

Answered: 1 week ago