3.5.1: Recursive function: Writing the base case.   Add an if branch to complete double_pennies()'s base case. Sample output with inputs: 1 10 Number of pennies after 10 days: 1024 # Returns number of pennies if pennies are doubled num_days times def double_pennies(num_pennies, num_days):     total_pennies = 0     if "solution goes here"     else:         total_pennies = double_pennies((num_pennies * 2), (num_days - 1))     return total_pennies # Program computes pennies if you have 1 penny today, # 2 pennies after one day, 4 after two days, and so on starting_pennies = int(input()) user_days = int(input()) print('Number of pennies after', user_days, 'days: ', end="") print(double_pennies(starting_pennies, user_days))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
3.5.1: Recursive function: Writing the base case.
 
Add an if branch to complete double_pennies()'s base case.

Sample output with inputs: 1 10
Number of pennies after 10 days: 1024

# Returns number of pennies if pennies are doubled num_days times
def double_pennies(num_pennies, num_days):
    total_pennies = 0

    if "solution goes here"

    else:
        total_pennies = double_pennies((num_pennies * 2), (num_days - 1))

    return total_pennies

# Program computes pennies if you have 1 penny today,
# 2 pennies after one day, 4 after two days, and so on
starting_pennies = int(input())
user_days = int(input())

print('Number of pennies after', user_days, 'days: ', end="")
print(double_pennies(starting_pennies, user_days))

 
 
CTU Assignment List
zy Section 3.5 - CS 219T: Python Pro X
CTU Messenger
b Computer Engineering Questions X
learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5
=zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion
zyBooks catalog
I dise
Feedback?
CHALLENGE
3.5.1: Recursive function: Writing the base case.
ACTIVITY
Add an if branch to complete double_pennies()'s base case.
Sample output with inputs: 1 10
Number of pennies after 10 days: 1024
Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program
end never reached." The system doesn't print the test case that caused the reported message.
409106.2543518.qx3zqy7
1 # Returns number of pennies if pennies are doubled num_days times
1 test
2 def double pennies (num_pennies, num_days):
passed
3
total_pennies = 0
4
5
if ((num_pennies <= 0) or (num_days == 0)):
All tests
6
passed
7
else:
8
total_pennies = double_pennies ((num_pennies 2), (num_days - 1))
9
10
return total_pennies
11
12 # Program computes pennies if you have 1 penny today,
13 # 2 pennies after one day, 4 after two days, and so on
14 starting_pennies = int(input())
15 user_days = int(input())
16
17 print('Number of pennies after', user days, 'days: end
+
? Help/FAQ
Stacey Queen
X
:
11:40 PM
6/19/2022
Transcribed Image Text:CTU Assignment List zy Section 3.5 - CS 219T: Python Pro X CTU Messenger b Computer Engineering Questions X learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5 =zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion zyBooks catalog I dise Feedback? CHALLENGE 3.5.1: Recursive function: Writing the base case. ACTIVITY Add an if branch to complete double_pennies()'s base case. Sample output with inputs: 1 10 Number of pennies after 10 days: 1024 Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message. 409106.2543518.qx3zqy7 1 # Returns number of pennies if pennies are doubled num_days times 1 test 2 def double pennies (num_pennies, num_days): passed 3 total_pennies = 0 4 5 if ((num_pennies <= 0) or (num_days == 0)): All tests 6 passed 7 else: 8 total_pennies = double_pennies ((num_pennies 2), (num_days - 1)) 9 10 return total_pennies 11 12 # Program computes pennies if you have 1 penny today, 13 # 2 pennies after one day, 4 after two days, and so on 14 starting_pennies = int(input()) 15 user_days = int(input()) 16 17 print('Number of pennies after', user days, 'days: end + ? Help/FAQ Stacey Queen X : 11:40 PM 6/19/2022
CTU Assignment List
zy Section 3.5 - CS 219T: Python Pro X SCTU Messenger
b Computer Engineering Questions X
+
✰ learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5
=zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion
zyBooks catalog
Sample Output with inputs. I TU
Number of pennies after 10 days: 1024
Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program
end never reached." The system doesn't print the test case that caused the reported message.
409106.2543518.qx3zqy7
1 # Returns number of pennies if pennies are doubled num_days times
2 def double pennies (num_pennies, num_days):
1 test
3
total_pennies = 0
passed
4
5
"solution goes here"
All tests
6
passed
7
else:
8
total_pennies
=
double_pennies ((num_pennies * 2), (num_days - 1))
9
10
return total pennies
11
12 # Program computes pennies if you have 1 penny today,
13 # 2 pennies after one day, 4 after two days, and so on
14 starting_pennies = int(input())
15 user_days = int(input())
16
17 print('Number of pennies after', user_days, 'days: ', end="")
18 print (double_pennies (starting_pennies, user_days))
Run X Not all tests passed
X Test aborted
Exited with return code 1.
File "main.py", line 7
else:
? Help/FAQ
Stacey Queen
X
:
11:40 PM
6/19/2022
Transcribed Image Text:CTU Assignment List zy Section 3.5 - CS 219T: Python Pro X SCTU Messenger b Computer Engineering Questions X + ✰ learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5 =zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion zyBooks catalog Sample Output with inputs. I TU Number of pennies after 10 days: 1024 Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message. 409106.2543518.qx3zqy7 1 # Returns number of pennies if pennies are doubled num_days times 2 def double pennies (num_pennies, num_days): 1 test 3 total_pennies = 0 passed 4 5 "solution goes here" All tests 6 passed 7 else: 8 total_pennies = double_pennies ((num_pennies * 2), (num_days - 1)) 9 10 return total pennies 11 12 # Program computes pennies if you have 1 penny today, 13 # 2 pennies after one day, 4 after two days, and so on 14 starting_pennies = int(input()) 15 user_days = int(input()) 16 17 print('Number of pennies after', user_days, 'days: ', end="") 18 print (double_pennies (starting_pennies, user_days)) Run X Not all tests passed X Test aborted Exited with return code 1. File "main.py", line 7 else: ? Help/FAQ Stacey Queen X : 11:40 PM 6/19/2022
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

After working this code, this is the error code that popped up resulted in half right.   Traceback (most recent call last): File "main.py", line 292, in <module> print(double_pennies(starting_pennies, user_days)) File "main.py", line 264, in double_pennies total_pennies = double_pennies((num_pennies * 2), (num_days - 1)) File "main.py", line 264, in double_pennies total_pennies = double_pennies((num_pennies * 2), (num_days - 1)) File "main.py", line 264, in double_pennies total_pennies = double_pennies((num_pennies * 2), (num_days - 1)) [Previous line repeated 995 more times] File "main.py", line 260, in double_pennies if num_days == 1: RecursionError: maximum recursion depth exceeded in comparison

zy Section 3.5 - CS 219T: Python Pro X b Answered: 3.5.1: Recursive functi X +
learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5
CTU Class Homepage.
= zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion
3.52 Recursive fun....png
zyBooks catalog
Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program
end never reached." The system doesn't print the test case that caused the reported message.
409106.2543518.qx3zqy7
1 # Returns number of pennies if pennies are doubled num_days times
2 def double pennies (num_pennies, num_days):
1 test
passed
3
total_pennies = 0
4
if num_days == 1:
5
return num_pennies * 2
6
else:
All tests
passed
7
total_pennies = double_pennies ((num_pennies * 2), (num_days - 1))
8
9
return total_pennies
10
11 # Program computes pennies if you have 1 penny today,
12 # 2 pennies after one day, 4 after two days, and so on
13 starting_pennies = int(input())
14 user_days = int(input())
15
16 print('Number of pennies after', user_days, 'days: ', end="")
17 print (double_pennies (starting_pennies, user_days))
Run X Not all tests passed
✓ Testing with inputs: 1 10
Your output
Number of pennies after 10 days: 1024
✓ Testing with inputs: 1 40
? Help/FAQ
Stacey Queen
Show all
X
:
X
5:19 PM
6/20/2022
Transcribed Image Text:zy Section 3.5 - CS 219T: Python Pro X b Answered: 3.5.1: Recursive functi X + learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5 CTU Class Homepage. = zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion 3.52 Recursive fun....png zyBooks catalog Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message. 409106.2543518.qx3zqy7 1 # Returns number of pennies if pennies are doubled num_days times 2 def double pennies (num_pennies, num_days): 1 test passed 3 total_pennies = 0 4 if num_days == 1: 5 return num_pennies * 2 6 else: All tests passed 7 total_pennies = double_pennies ((num_pennies * 2), (num_days - 1)) 8 9 return total_pennies 10 11 # Program computes pennies if you have 1 penny today, 12 # 2 pennies after one day, 4 after two days, and so on 13 starting_pennies = int(input()) 14 user_days = int(input()) 15 16 print('Number of pennies after', user_days, 'days: ', end="") 17 print (double_pennies (starting_pennies, user_days)) Run X Not all tests passed ✓ Testing with inputs: 1 10 Your output Number of pennies after 10 days: 1024 ✓ Testing with inputs: 1 40 ? Help/FAQ Stacey Queen Show all X : X 5:19 PM 6/20/2022
zy Section 3.5 - CS 219T: Python Pro X b Answered: 3.5.1: Recursive functi X +
CTU Class Homepage.
learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5
=zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion
Testing with inputs: 1 10
Your output
✓ Testing with inputs: 1 40
Your output
✓ Testing with inputs: 1 1
X Test aborted
3.52 Recursive fun....png
Number of pennies after 10 days: 1024
Number of pennies after 40 days: 1099511627776
Your output Number of pennies after 1 days: 2
File "main.py", line 292, in <module>
print (double_pennies (starting_pennies, user_days))
File "main.py", line 264, in double pennies
(num_days - 1))
total_pennies = double_pennies ((num_pennies * 2),
File "main.py", line 264, in double pennies
total_pennies = double_pennies ((num_pennies * 2), (num_days - 1))
File "main.py", line 264, in double pennies
total_pennies = double_pennies ((num_pennies * 2), (num_days - 1))
[Previous line repeated 995 more times]
File "main.py", line 260, in double pennies
zyBooks catalog
? Help/FAQ
Stacey Queen
Show all
X
:
X
5:19 PM
6/20/2022
Transcribed Image Text:zy Section 3.5 - CS 219T: Python Pro X b Answered: 3.5.1: Recursive functi X + CTU Class Homepage. learn.zybooks.com/zybook/CS219-2203A-03-2203A/chapter/3/section/5 =zyBooks My library > CS 219T: Python Programming home > 3.5: Creating recursion Testing with inputs: 1 10 Your output ✓ Testing with inputs: 1 40 Your output ✓ Testing with inputs: 1 1 X Test aborted 3.52 Recursive fun....png Number of pennies after 10 days: 1024 Number of pennies after 40 days: 1099511627776 Your output Number of pennies after 1 days: 2 File "main.py", line 292, in <module> print (double_pennies (starting_pennies, user_days)) File "main.py", line 264, in double pennies (num_days - 1)) total_pennies = double_pennies ((num_pennies * 2), File "main.py", line 264, in double pennies total_pennies = double_pennies ((num_pennies * 2), (num_days - 1)) File "main.py", line 264, in double pennies total_pennies = double_pennies ((num_pennies * 2), (num_days - 1)) [Previous line repeated 995 more times] File "main.py", line 260, in double pennies zyBooks catalog ? Help/FAQ Stacey Queen Show all X : X 5:19 PM 6/20/2022
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education