My Code is not getting the correct output.  Here is the lab assignement : 1.27 LAB: Exact change - functions   Define a function called exact_change that takes the total change amount in cents and calculates the change

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

My Code is not getting the correct output.  Here is the lab assignement :

1.27 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 0 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 1 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)

MY CODE:

def exact_change(user_total):
    num_dollars = user_total //100
    user_total %= 100
    num_quarters = user_total // 25
    user_total %= 25
    num_dimes = user_total //10
    user_total %= 10
    num_nickels = user_total //5
    user_total %= 5
    num_pennies=user_total
    return(num_dollars, num_quarters, num_dimes, num_nickels, num_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 <= 0:
        print("no change")

    else:
        if num_dollars > 1:
            print('%d dollars' % num_dollars)
        elif num_dollars == 1:
            print('%d dollar' % num_dollars)
            
        if num_quarters > 1:
            print('%d quarters' % num_quarters)
        elif num_quarters == 1:
            print('%d quarter' % num_quarters)
            
        if num_dimes > 1:
            print('%d dimes' % num_dimes)
        elif num_dimes == 1:
            print('%d dime' % num_dimes)
            
        if num_nickels > 1:
            print('%d nickels' % num_nickels)
        elif num_nickels == 1:
            print('%d nickel' % num_nickels)
            
        if num_pennies > 1:
            print('%d pennies' % num_pennies)
        elif num_dimes == 1:
            print('%d penny' % num_pennies)


ERRORS ATTACHED

Safari
File
Edit
View
History
Bookmarks
Develop
Window
Help
Sat Apr 16 6:01 PM
R O
learn.zybooks.com
00
O OneLogin
Course Modules: CS 161B-101: Fou...
Inbox - smize1@eou.edu - Eastern...
zy Section 1.27 - CS 161B: Foundation...
All Channels - Xfinity Stream
> CS 161B: Foundations of CS 1B home >
= zyBooks
My library
1.27: LAB: Exact change - functions
E zyBooks catalog
? Help/FAQ
sherrie mize
3: Compare output ^
0/2
Output differs. See highlights below.
Input
156
1 dollar
Your output
2 quarters
1 nickel
1 penny
Expected output
1 nickel
6 quarters
4: Unit test
0/3
exact_change(300). Should return 0, 0, 0, 12
exact change (300) did not return four values.
Test feedback
Your function may be missing a return statement or
returned an incorrect amount of values.
APR
3
16
étv
Transcribed Image Text:Safari File Edit View History Bookmarks Develop Window Help Sat Apr 16 6:01 PM R O learn.zybooks.com 00 O OneLogin Course Modules: CS 161B-101: Fou... Inbox - smize1@eou.edu - Eastern... zy Section 1.27 - CS 161B: Foundation... All Channels - Xfinity Stream > CS 161B: Foundations of CS 1B home > = zyBooks My library 1.27: LAB: Exact change - functions E zyBooks catalog ? Help/FAQ sherrie mize 3: Compare output ^ 0/2 Output differs. See highlights below. Input 156 1 dollar Your output 2 quarters 1 nickel 1 penny Expected output 1 nickel 6 quarters 4: Unit test 0/3 exact_change(300). Should return 0, 0, 0, 12 exact change (300) did not return four values. Test feedback Your function may be missing a return statement or returned an incorrect amount of values. APR 3 16 étv
Safari
File
Edit
View
History
Bookmarks
Develop
Window
Help
Sat Apr 16 6:01 PM
R O
learn.zybooks.com
00
O OneLogin
Course Modules: CS 161B-101: Fou...
Inbox - smize1@eou.edu - Eastern...
zy Section 1.27 - CS 161B: Foundation...
All Channels - Xfinity Stream
> CS 161B: Foundations of CS 1B home >
= zyBooks
My library
1.27: LAB: Exact change - functions
E zyBooks catalog
? Help/FAQ
sherrie mize
3: Compare output ^
0/2
Output differs. See highlights below.
Input
156
1 dollar
Your output
2 quarters
1 nickel
1 penny
Expected output
1 nickel
6 quarters
4: Unit test
0/3
exact_change(300). Should return 0, 0, 0, 12
exact change (300) did not return four values.
Test feedback
Your function may be missing a return statement or
returned an incorrect amount of values.
APR
3
16
étv
Transcribed Image Text:Safari File Edit View History Bookmarks Develop Window Help Sat Apr 16 6:01 PM R O learn.zybooks.com 00 O OneLogin Course Modules: CS 161B-101: Fou... Inbox - smize1@eou.edu - Eastern... zy Section 1.27 - CS 161B: Foundation... All Channels - Xfinity Stream > CS 161B: Foundations of CS 1B home > = zyBooks My library 1.27: LAB: Exact change - functions E zyBooks catalog ? Help/FAQ sherrie mize 3: Compare output ^ 0/2 Output differs. See highlights below. Input 156 1 dollar Your output 2 quarters 1 nickel 1 penny Expected output 1 nickel 6 quarters 4: Unit test 0/3 exact_change(300). Should return 0, 0, 0, 12 exact change (300) did not return four values. Test feedback Your function may be missing a return statement or returned an incorrect amount of values. APR 3 16 étv
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY