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))
Sample output with inputs: 1 10
# 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
#
# 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))
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
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