The code you've posted shows no indentation at all. Remember, for Python, indentation matters.
After indenting your code, you are still facing two bugs:
- you are using
input
, which means you are using Python3 OR you should have been using raw_input
. See this discussion, which explains the difference very well. If you are using Python3, then it's not correct to use the print
statement: you should be using the print
function. If you're using Python2, you should be using raw_input
.
- Your function,
factorial
, expects a number, yet you are passing it a string (which is the return value of raw_input
and input
). Convert to int first.
This code is properly indented and works on Python3. Use raw_input
rather than input
if you're working with Python2.
def factorial(number):
result = 1
while number > 0:
result = result*number
number = number- 1
return result
in_variable = input("Enter a number to calculate the factorial of")
print(factorial(int(in_variable)))