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

724 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Explain how python programs are structured and give an example of how methods are initiated


With the help of Pandas and Numpy library create a DataFrame with the columns "Name", "Surname", "Age" and "Gender", create as many rows as you want. Print out the result.


Write a function that checks whether a number is prime or not.


How might we implement the bubble sort algorithm in Python


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–2024

Terms & Conditions|Privacy Policy