Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.

def factorial(x): #base case if x == 1:    return 1 #recursive call  else:    return (x * factorial(x-1))Recursive algorithms are written using a strategy called divide and conquer. You try and break the problem up into a small repeatable sub-task.

CS

Related Python Mentoring answers

All answers ▸

Write a recursive function to find the factorial of a number n.


Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.


Give a segment of python code that will print the numbers 1 to 7, each one on a new line


How would you loop over every key and value in a python dictionary?