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