Write python code to complete factorial_str()'s recursive case. Sample output with input: 55! = 5 * 4 * 3 * 2 * 1 = 120 def factorial_str(fact_counter, fact_value): output_string = '' if fact_counter == 0: # Base case: 0! = 1 output_string += '1' elif fact_counter == 1: # Base case: print 1 and result output_string += str(fact_counter) + ' = ' + str(fact_value) else: # Recursive case output_string += str(fact_counter) + ' * ' next_counter = fact_counter - 1 next_value = next_counter * fact_value output_string += '''Need help here to get the proper output''' return output_string user_val = int(input()) print('{}! = '.format(user_val), end="") print(factorial_str(user_val, user_val))
Write python code to complete factorial_str()'s recursive case.
Sample output with input: 55! = 5 * 4 * 3 * 2 * 1 = 120
def factorial_str(fact_counter, fact_value):
output_string = ''
if fact_counter == 0: # Base case: 0! = 1
output_string += '1'
elif fact_counter == 1: # Base case: print 1 and result
output_string += str(fact_counter) + ' = ' + str(fact_value)
else: # Recursive case
output_string += str(fact_counter) + ' * '
next_counter = fact_counter - 1
next_value = next_counter * fact_value
output_string += '''Need help here to get the proper output'''
return output_string
user_val = int(input())
print('{}! = '.format(user_val), end="")
print(factorial_str(user_val, user_val))
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images