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
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 changeEx: If the input is:
45the output is:
2 dimes 1 quarterYour 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd6ded41a-9f92-4a9d-b437-015644cf6784%2F135cb55a-b735-47e6-93de-372a9c4391d8%2Ftxgvi6m_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd6ded41a-9f92-4a9d-b437-015644cf6784%2F135cb55a-b735-47e6-93de-372a9c4391d8%2F337dg7_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)