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.

Answered by Conor S. Python tutor

1042 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

How do For Loops work?


Create a program that takes in two numbers and returns the highest of the two


[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences