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

def factorial(n):               if n == 1 or n == 0:                               return 1               else:                               return n * factorial(n-1)

MB

Related Python Mentoring answers

All answers ▸

How could I write a program to convert Km/h to m/s in python


What would you expect to be the output of the following code snippet: `a = [1, 2, 3]; b = a; b[1] = 4; print(a); print(b);`, and why?


Firstly, my question is not Python related, but maths A-level related. I don't know how to change that in my profile but I would like to only tutor maths GCSE and potentially A-level. My question: Integrate sin(x)^3 over x=0 and x=pi/2.


Given a list of N numbers, use a single list comprehension to produce a new list that only contains those values that are: (a) even numbers, and (b) from elements in the original list that had even indices .