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 basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)


How does a for loop work in Python?


How do you write code to implement a recursive fibonacci algorithm?


Write a program that computes the sum of all numbers up to a input number n