Write code to complete doublepenniess base case Sample outpu

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.

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

    \'\'\'Your 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 = 1
user_days = 10

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

Solution

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

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 act

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site