Factorial cancer


Simple as it can be and I dont know why my code is wrong:

def factorial(x):

  while x >= 0:

    y = (x * (x -1))
  if x = 0:
    return x+1
  return y

File “python”, line 7
if x = 0:
IndentationError: unexpected indent

99% of errors I get is about indentation, i think its the worst side of a python :confused:


The value of x never changes, which is why you have an infinite loop. The given indentation error nothwithstanding.

or best. Ruby forces us to use blocks in {} or with end as a trade-off. Once you get in the habit of thinking in blocks of this style it all becomes natural. Small hurdle to cross, imho.


Ah, ok now it have a sense at least.
Using function inside itself was tricky but I got it, thx for replying.
Take care!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.