Question
Need help with this code Here is my code: def exact_change(user_total): dollars = user_total // 100 user_total %= 100 quarters = user_total // 25 user_total
Need help with this code
Here is my code:
def exact_change(user_total): dollars = user_total // 100 user_total %= 100 quarters = user_total // 25 user_total %= 25 dimes = user_total // 10 user_total %= 10 nickels = user_total // 5 user_total %= 5 pennies = user_total return dollars, quarters, dimes, nickels, pennies
if __name__ == '__main__': input_val = int(input()) num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val) if input_val 1: print(num_pennies, 'pennies') elif num_pennies == 1: print(num_pennies, 'penny')
if num_nickels > 1: print(num_nickels, 'nickels') elif num_nickels == 1: print(num_nickels, 'nickel')
if num_dimes > 1: print(num_dimes, 'dimes') elif num_dimes == 1: print(num_dimes, 'dime')
if num_quarters > 1: print(num_quarters, 'quarters') elif num_quarters == 1: print(num_quarters, 'quarter')
if num_dollars > 1: print(num_dollars, 'dollars') elif num_dollars == 1: print(num_dollars, 'dollar')
I continue to get these errors:
1.30 LAB: Exact change - functions Define a function called exact_change that takes the total change amount in cents and calculates the change using the fewest coins. The coin types are pennies, nickels, dimes, and quarters. Then write a main program that reads the total change amount as an integer input, calls exact_change, and outputs the change, one coin type per line. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Output "no change if the input is O or less. Ex: If the input is: 0 (or less), the output is: no change Ex: If the input is: 45 the output is: 2 dimes i quarter Your program must define and call the following function. The function exact_change() should return num_pennies, num_nickels, num_dimes, and num_quarters. def exact_change (user_total) 3585301649854.qx3zqy7 LAB ACTIVITY 1.30.1: LAB: Exact change - functions 2/10 Input 45 Your output 1 quarter dimes Expected output 2 dimes 1 quarter 2: Compare output ^ 1/1 Input 0 Your output no change 3: Compare output ^ 0/2 Output differs. See highlights below. Special character legend Input 156 Your output 1 dollar 2 quarters 1 nickel penny Expected output 1 penny 1 nickel 6 quarters 4: Unit test A 0/3 exact_change(300). Should return 0, 0, 0,12 exact_change (300) did not return four values. Your function may be missing a return statement or Test feedback
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