Question: Project Description / Specification Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters,

Project Description / Specification

Your program must meet the following specifications:

1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies.

2. Repeatedly prompt the user for a price in the formxx.xx, wherexdenotes a digit, or to enter 'q' to

quit.

3. When a price is entered:

  1. 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').
  2. Prompt for the number of dollars in payment. If the payment is insufficient, print an error message and reprompt for payment.
  3. 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.
  4. 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.)
  5. In case exact payment is made, print a message such as "No change."
  6. If the change cannot be made up with the coins remaining, print an error message and halt the
  7. program

4. Just before quitting, print the total amount (the number of dollars and number of cents) left in the

stock.

Deliverables

The deliverable for this assignment is the following file:proj02.py-- your source code solution

Be sure to use the specified file name and to submit it for grading via the Mimir before the project deadline

Notes and Hints:

1. To clarify the project specifications, sample output is appended to the end of this document.

2. Items 1-6 of theCoding Standardwill be enforced for this project.

3. We provide aproj02.pyprogram for you to start with. It has a simplewhileloop (notice

how input is prompted before the loop and at the bottom of the loop.

4. Floating point numbers can be difficult to work with due to the imprecision of representing real

numbers in a finite number of computer-memory bits. To avoid imprecision do calculations in cents, i.e. as typeint. For example, $1.15 is the same as 115 cents. To see the problem, try evaluating1.15*100in the Python shell and compare that to evaluatinground(1.15*100).

5. There are many ways to calculate the maximum number of quarters to make change using the greedy algorithm.

  1. One is with awhileloop where you keep subtracting 25 from the amount of change due
  2. 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.
  3. Alternatively, use the quotient (//) operation for integers for finding the numbers of each coin. For example, 195//25 is 7, the most number 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 stock. 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.

6. When we learn about formatting strings, we can more easily and elegantly print monetary amounts. For now, just use the Pythonprint(...) command with appropriate string and/or integer arguments to print the number of dollars and the number of cents.

7. One tricky control issue is how to end the program if you run out of coins in the stock. The sampleproj02.pyprogram provides a clue with theempty_stockBoolean. The problem is thatbreakonly breaks out of the current, innermost loop whereas you may be within multiple loops so when youbreakyou can set theempty_stockBoolean toTrueand use that to break out of the enclosing loops.

8. You do not need to check for any input errors other than those mentioned in this description. 9. You may not use advanced data structures such as lists, dictionaries, sets or classes in solving

this problem.

Sample Interaction:

Test 1

Welcome to change-making program.

Stock: 10 quarters, 10 dimes, 10 nickels, and 10 pennies Enter the purchase price (xx.xx) or 'q' to quit: 1.5

Input dollars paid (int): 2 

Collect change below:

Quarters: 2

Stock: 8 quarters, 10 dimes, 10 nickels, and 10 pennies

Enter the purchase price (xx.xx) or 'q' to quit: q

Test 2

Welcome to change-making program.

Stock: 10 quarters, 10 dimes, 10 nickels, and 10 pennies Enter the purchase price (xx.xx) or 'q' to quit: 2

Input dollars paid (int): 2 

No change.

Stock: 10 quarters, 10 dimes, 10 nickels, and 10 pennies

Enter the purchase price (xx.xx) or 'q' to quit: q

Test 3

Welcome to change-making program.

Stock: 10 quarters, 10 dimes, 10 nickels, and 10 pennies Enter the purchase price (xx.xx) or 'q' to quit: 1.5

Input dollars paid (int): 5 

Collect change below: Quarters: 10

Dimes: 10

Stock: 0 quarters, 0 dimes, 10 nickels, and 10 pennies

Enter the purchase price (xx.xx) or 'q' to quit: 0.5

Input dollars paid (int): 2

Error: ran out of coins.

Test 4

Welcome to the change-making program.

Enter the purchase price (xx.xx) or `q' to quit: -1.20 Error: purchase price must be non-negative.

Enter the purchase price (xx.xx) or `q' to quit: 1.43

Input dollars paid (int): 1

Error: insufficient payment.

Input dollars paid (int): 2 

Collect change below:

Quarters: 2

Nickels: 1

Pennies: 2

Stock: 8 quarters, 10 dimes, 9 nickels, and 8 pennies

Enter the purchase price (xx.xx) or `q' to quit: 0.13

Input dollars paid (int): 1

Collect change below:

Quarters: 3

Dimes: 1

Pennies: 2

Stock: 5 quarters, 9 dimes, 9 nickels, and 6 pennies

Enter the purchase price (xx.xx) or `q' to quit: 2.22

Input dollars paid (int): 4

Collect change below:

Quarters: 5

Dimes: 5

Pennies: 3

Stock: 0 quarters, 4 dimes, 9 nickels, and 3 pennies

Enter the purchase price (xx.xx) or `q' to quit: q

Test 5

Blind test

Scoring Rubric

Computer Project #02 General Requirements Scoring Summary 

______ 5 pts Coding Standard

(descriptive comments, mnemonic identifiers, format, etc...)

Implementation: __0__ (12 pts) __0__ (12 pts) __0__ (12 pts) __0__ (12 pts) __0__ (12 pts) 

TA Comments:

Test Case 1: Test Case 2: Test Case 3: Test Case 4: Test Case 5: Blind Test 

proj02.py:

# purchase price and payment will be kept in cents quarters = 10 dimes = 10 nickels = 10 pennies = 10 print(" Welcome to change-making program.") print(" Stock: {} quarters, {} dimes, {} nickels, and {} pennies".format( quarters, dimes, nickels, pennies)) in_str = input("Enter the purchase price (xx.xx) or 'q' to quit: ") while in_str != 'q': # Fill in the good stuff here instead of the following print print("Testing:",in_str) print(" Stock: {} quarters, {} dimes, {} nickels, and {} pennies".format( quarters, dimes, nickels, pennies)) in_str = input("Enter the purchase price (xx.xx) or 'q' to quit: ") 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!