5. Factorial


I'm having troubles with the factorial exercise:


It calculates the factorial correctly (a 24 for x=4, a 120 for x=5, etc...) but then I get this error:

Oops, try again. factorial(1) resulted in an error: invalid literal for int() with base 10: ''

Any idea on why this keeps happening? Thanks in advance.

def factorial(x):
    x=int(raw_input("Number?")) #Number
    f=x #Factorial 
    while x > 1:
    print "The factorial is" , f
    return f


don't overwrite the function parameter, if you want to prompt the user for a number, do this outside the function:

x=int(raw_input("Number?")) #Number

and pass the variable as argument when calling the function


It works! Thank you! :smiley: