Hey, why?


#1

Hi guys, I am trying to build a factorial function, but for some reason my “for” does not go through all the numbers in the range(). Ideas?

def factorial(x):
  jerry = x + 1
  if x == 1:
    return 1
  else:
    total = 1
    for t in range(1, jerry):
      print t
      total = total * (t+1)
      return total

#2

That line should not be inside the loop.


#3

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