5.factorial


#1



how do i do this?:
Define a function factorial that takes an integer x as input.

Calculate and return the factorial of that number.


#2

The forum is to help you, not code for you.

How do think you could tackle this problem? Maybe create a variable to store the result? A loop for all the multiplications? Please post your code so we can help you


#3

def factorial(x):
return x * x - 1


#4

lets say x is 5, we want to return 120 (5*4*3*2*1)

your function would return 20.

You will need to create a total variable (give it a value of 1), then add a loop, to get all the values from x till 1, each time multiplying it with total to get to return, for example, 120 if x is 5

note: 5 is just an example, the exercise will test multiply values


#7

so is factorial(x-1) the iterator for this loop? That's the only way it makes sense to me.


#9

nope, but you could use a recursive function call to solve this problem. Or include a while or a for loop


#10

def factorial(x):
if x==0:
return 1
else:
return x*factorial(x-1)
tanks