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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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