Calculate the numbers of coins of each denomination

Assignment Help Python Programming
Reference no: EM132587287

Assignment Overview

This assignment will give you more experience on the use of:
1. integers (int)
2. floats (float)
3. conditionals
4. iteration
Your program will calculate change. It will start with a stock of coins. It will then repeatedly request the price for an item to be purchased or to quit. If a price is input, it will prompt for dollars in payment and print the change due using the minimum number of coins possible. Before quitting, it will display the value of coins remaining in the stock. An example interaction with our program appears at the end of this description.

Background
The algorithm for calculating the numbers of coins of each denomination to dispense so as to minimize the total number of coins is an example of a greedy algorithm. You start by figuring out the most number of quarters you can dispense (without exceeding the amount), then the most number of dimes, then the number of nickels and finally pennies. If you are curious, you can read about the Greedy Algorithm.

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 form xx.xx, where xdenotes a digit, or to enter ‘q' to quit.
3. When a price is entered:
a. 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').
b. Prompt for the number of dollars in payment. If the payment is insufficient, print an error message and reprompt for payment.
c. 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.
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
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 the Coding Standard will be enforced for this project.
3. We provide a proj02.py program for you to start with. It has a simple while loop (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 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).

5. 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.
b. 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 Python print(...) 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 sample proj02.py program provides a clue with the empty_stock Boolean. The problem is that break only breaks out of the current, innermost loop whereas you may be within multiple loops so when you break you can set the empty_stock Boolean to True and 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 Scoring Summary
General Requirements
______ 5 pts Coding Standard
(descriptive comments, mnemonic identifiers, format, etc...)
Implementation:
__0__ (12 pts) Test Case 1:
__0__ (12 pts) Test Case 2:
__0__ (12 pts) Test Case 3:
__0__ (12 pts) Test Case 4:
__0__ (12 pts) Test Case 5: Blind Test

Reference no: EM132587287

Questions Cloud

Context of authoritarian theory : Analyze any event and discuss the reportage of media in the context of Authoritarian theory
What type of critical infrastructure data collection : Identify what type of critical infrastructure data collection is needed for pavement and storm water management facilities.
What will happen to the eur-pst exchange rate : Based on the above information, please explain what will happen to the EUR----PST exchange rate.
Describe what are smart contracts : Discuss the following: 1. What are Smart Contracts and how might they be applied in human resource management? You are required to cite this week's assigned.
Calculate the numbers of coins of each denomination : Calculate the numbers of coins of each denomination to dispense so as to minimize the total number of coins is an example of a greedy algorithm
Prepare journal entries relating to the stock option plan : Prepare journal entries relating to the stock option plan for the years 2016 through 2019. Assume that the employees perform services equally
Focus for information governance efforts : We learned that e-mail is a major area of focus for information governance (IG) efforts, and has become the most common business software application
Explain market fail-externalities : Explain market fail, externalities and optimality in economics.
How you would go about gathering the information you need : Explain in your own words what "FOOTPRINTING" (or digital reconnaissance) is and how you would go about gathering the information you need to determine.

Reviews

Write a Review

Python Programming Questions & Answers

  Read the contents of the file and print the name

Read the contents of the file, print the name, standard sequence, reverse sequence and complement sequence. Limit the length of each line of sequence.

  Write the program that reads from a text file

Write the program that reads from a text file. Read each line and send it to the output file, preceded by line numbers. Whose fleece was white as snow.

  Create a dictionary containing the us states as keys

Prepare a Program that creates a dictionary containing the U.S. states as keys and their capitals as values. You need to store the capitals and states.

  What would happen if the script fails to open password file

You have been hired by a company to provide consultation on security and provide recommendations. Using Microsoft® Word, write a 1-page document explaining.

  Write a program using python that asks the user to enter

Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50%

  Find a python script

Find a python script

  Write a program that prints a list with all items separated

Assignment states "Write a program that prints a list with all the items separated by a comma and a space, with and inserted before the last item.

  Write a program that does simple packet routing

Write a program that does simple packet routing and your program will take three command-line arguments:

  Write a program that prompts for a speed limit and clocked

Write a program that prompts for a speed limit and clocked speed and either prints a message saying that the speed is legal or prints the amount.

  Design a program that asks the user to enter 10 golf scores

Design a program that asks the user to enter 10 golf scores. The scores should be stored in an Integer array. Sort the array in ascending order and display.

  Without using the system function to call any bash commands

without using the system function to call any bash commands write a python program that will implement a simple version

  Write python expressions corresponding to the sum

Write Python expressions corresponding to the sum of the first five positive integers and The remainder when 403 is divided by 73.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd