Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm working with Python in the Linux command line, and I really need some help solving these three questions, please. Thank you! 1) Write

Hi, I'm working with Python in the Linux command line, and I really need some help solving these three questions, please. Thank you!

1) Write a Python script that uses a function to return the amount of change made from a given string of coin values. The function should take in the change due as an argument and the list of currency values and return a dictionary of the coin values.

Input string

Expected output of script

Enter a value: 13.37

Enter coins: 1, .20, .10, .05, .01

{'1 coin': 13, '.20 coin': 1, '.10 coin': 1, '.05 coin': 1, '.01 coin': 2}

2) Write a Python script that will calculate the change due, if any, for a given payment and for a random cost, based on a given string of coin values. If the payment is made with exact change, no change will be due. If the payment is over the total amount, then the output will be the change due. If the payment is under the total amount, the output will be how much more is needed. Your script should also provide input checking to ensure that only digits are being entered and are in the correct format before doing any calculations and it should loop continuously until the user enters "quit.

Input string

Expected output of script

Cost is 17.61

Enter a payment: 15.25

Enter a list of coin values: 1, .35, .23, .12, .03, .01

Cost is 7.88

Enter a payment: 20.00

Enter a list of coin values: 1, .35, .23, .12, .03, .01

Cost is 45.25

Enter a payment: quit

needed: 2 1 coins, 1 .35 coins, 1 .01 coins,

change: 12 1 coins, 1 .12 coins,

Goodbye!

3) Write a Python script that uses a function to test a given input value and return whether it is enough to cover a purchase of $14.85. Your script should take in the amount due as an argument and continually prompt the user to enter their payment. The function should compare the payment to the cost, print whether it is over or under and by how much, and if it is too much it should then return the difference.

Input string

Expected output of script

Enter a number: 12.89

Enter a number: 14.85

Enter a number: 25.13

That is not enough by 1.96

That is exactly enough

There is change due of 10.28

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions