Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python! Write code to complete double_pennies()\'s base case. Sample output for

ID: 3932763 • Letter: P

Question

Python! Write code to complete double_pennies()'s base case. Sample output for below program:



Note: These activities may test code with different test values. This activity will perform four tests, with starting_pennies = 1 and user_days = 10, then with starting_pennies = 1 and user_days = 40, then with starting_pennies = 1 and user_days = 1, then with starting_pennies = 1 and user_days = 0. See How to Use zyBooks.

Also 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.

Explanation / Answer

def double_pennies(num_pennies, num_days):
total_pennies = 0

'''Your solution goes here'''

if num_days == 0 :
return num_pennies;

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 = 1
user_days = 10
print('Number of pennies after', user_days, 'days: ', end="")
print(double_pennies(starting_pennies, user_days))

Output:

Number of pennies after 10 days: 1024