Change Calculator Task: Create a program that will input a price and a money amount. The program will...

70.2K

Verified Solution

Question

Programming

Change Calculator

Task:

Create a program that will input a price and a money amount. Theprogram will then decide if there is any change due and calculatehow much change and which coins to hand out. Coins will bepreferred in the least number of coins (starting with quarters andworking your way down to pennies).

Input:

total_price, amount_tender
allow the user to input 'q' for either value if they want to quitthe program

Validate:

total_price

  • cannot be negative
  • cannot be 0
  • cannot be text (other than q for quit)

amount_tender

  • cannot be less than total_price
  • can be equal to total_price
  • cannot be text (other than q for quit)

Output:

change_amount
number_quarters
number_dimes
number_nickels
number_pennies

IF any of these values is zero, DO NOT output that value. IE: ifthe change is 26 cents you only need to tell the user they willreceive 1 quarter and 1 penny. No more, no less.

Hint:

Use modular division to track the remainder after calculatingeach number of coins.

Convert the decimal to a whole number to make the calculationeasier. Use math.floor() to round DOWN to the nearest integer.

Use a try-catch (try-except) to help validate input. Try to setthe input value into afloat and if it does not fit then you cantest the input further without an error stopping your program.

Requirements:

Use a function

Use a loop

Validate all input

Use an IF statement

Use helpful, human-readable text both to prompt for input, butalso to let the user know about invalid inputs. Simply stating itis invalid doesn't help the user to correct their error.

If you can make your program also calculate the number ofdollars for change. That is, change above 99 cents.

Turn IN:

Python file ONLY

Answer & Explanation Solved by verified expert
3.6 Ratings (614 Votes)
In case of any queriesplease comment I would be very happy toassist all your queriesPlease give a Thumps up if you like theanswerProgramimport sysdef calcCoinsmoneybackquarter 025dime 010nickel 005penny 001moneybacknewmoneybackintmoneybackquartermoneyback intmoneybacknew quarterpartialtotal moneybacknew quartermoneyback quarterdimesmoneyback intpartialtotal dimedpartialtotal partialtotal dimesmoneyback dimenickelmoneyback intdpartialtotal nickelnpartialtotal dpartialtotal nickelmoneyback nickelpennymoneyback intnpartialtotal pennypennypartialtotal npartialtotal pennymoneyback    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students