Why am i getting this output


#1
def factorial(x):
  while x > 0:
      for i in range(1,x):
          x = x * i
      print(x)
      
factorial(5)    

Output:
120
6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000


#2

i am surprised you got output at all. Not sure i want to run your code, looks like an infinity loop

while x > 0 is always going to be true for x=5, so the while loop will cause an infinite number of iterations of your for loop, causing a massive number (i guess the number became so big, python had to stop the loop)


#3

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