+ 1

Why is this code not working??

I was making a code which outputs factorial of a given number. For eg: 5! = 1*2*3*4*5 But there seems an error which I can't find. Could somebody help?? def factorial(n):     result = 1     for x in range(1, n+1):         result = result * x     return result for n in range(1, 10):     print(n, factorial(n)) factorial(5) OUTPUT: SyntaxError: Invalid Syntax

8th Dec 2020, 1:34 PM
Advik
Advik - avatar
2 Respuestas
+ 1
Your space before result is weird and not considered a valid space in Python. Other than that, your code executes well.
8th Dec 2020, 1:39 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
CarrieForle , Ok, I get it... You made me understand in a fun way, Thanks a lot!!
8th Dec 2020, 1:42 PM
Advik
Advik - avatar