Question
PYTHON QUESTION Suppose you are given a list of coins in your cash register. You have a customer come to your register with $1.00 and
PYTHON QUESTION
Suppose you are given a list of coins in your cash register. You have a customer come to your register with $1.00 and a purchase worth $1.00 or less. You need to look in your cash register for the correct change and provide it to your customer.
Write a program to first ask for the name of a file containing the contents of your register and read from that file the list of all coins you have. Report the contents and then ask the user for the cost of the item they are purchasing. Assume they are paying with $1.00 and calculate the change they should receive using the coins in your register. Use larger values first, beginning with $0.50 and continuing through $0.25, $0.10, $0.05, and finally $0.01. In the end, either report the correct change or print a message saying that you cannot give correct change and print out what you need to satisfy the request.
To solve this problem, you will first read from a file how many coins you currently have using the function provided in hw3_util as follows:
import hw3_util coins = hw3_util.read_change('coins_01-03.txt') print(coins)
If you execute this code with the above file, you will get the coins list below.[50, 50, 50, 50, 50, 50, 25, 25, 10, 5, 1, 1]
A very easy way to solve this problem is to use the count() function of lists. For example, given the above list, coins.count(50) returns 6. You need to develop the code structure to decide how many of each coin you need based on the amount of change needed and the coins you actually have in your register.
Four examples of the program run (how it will look when you run it using Wing IDE 101) are provided in files hw3_part1_output_01.txt, hw3_part1_output_02.txt, hw3_part1_output_03.txt, and hw3_part1_output_04.txt. The first three examples make use of the coins file coins_01-03.txt. The fourth example uses coins_04.txt.
OUTPUT EXAMPLES:
hw3_util:
COINS TEXT:
hw3_part1_output_01.tx Enter the coin file name>coins_01-03.txt coins_01-03.txt Enter the item cost in cents (0-100) > 80 80 I have the following coins: [50, 50, 50, 50, 50, 50, 25, 25, 10, 5, 1, 1] Change from $1.00 is 20 cent:s I cannot make change with my current coins I need an additional 3 cents. hw3_part1_output_03.txt Enter the coin file name > coins_01-03.txt coins_01-03.txt Enter the item cost in cents (0-100) > 58 58 I have the following coins: [50, 50, 50, 50, 50, 50, 25, 25, 10, 5, 1, 1] Change from $1.00 is 42 cents 0 Half Dollars, 1 Quarters, 1 Dimes, 1 Nickels, 2 Pennies coins_01-03.txt 50, 6 25, 2 10, 1 5, 1 1, 2 coins_04.txt 50, 6 25, 2 10, 3 5, 0 1, 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started