Factorial


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/5?curriculum_id=4f89dab3d788890003000096#

Traceback (most recent call last):
File "python", line 9, in
NameError: name 'x' is not defined

it says x not defined.

Replace this line with your code. 

x=int(raw_input("Number"))
def factorial(x):
    
    f=x
    while x > 1:
        x=x-1
        f=f*x
     print "the factorial is",f
     return f
factorial(x)


#2

the error is this - File "python", line 8
print "the factorial is"
^
IndentationError: unindent does not match any outer indentation level


#3

File "python", line 8
print "the factorial is",f
^
IndentationError: unindent does not match any outer indentation level


#4

Indentation is very important in Python.

x=int(raw_input("Number"))
def factorial(x):
    f=x
    while x > 1:
        x=x-1
        f=f*x
        print "the factorial is",f
    return f # return ends the function, so this has to be unindented (out of the while loop)

factorial(x)

Do you understand?


#5

i understood that but it still throws an error in line 8.

File "python", line 8
print "the factorial is",f
^
IndentationError: unindent does not match any outer indentation level


#6

its done now. thanks much!


#11