Why is this code not working?? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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