How do I get the Math equation of Python Algorithm?

Posted by Gabriel on Stack Overflow See other posts from Stack Overflow or by Gabriel
Published on 2010-05-18T23:58:07Z Indexed on 2010/05/19 0:00 UTC
Read the original article Hit count: 262

Filed under:
|
|

ok so I am feeling a little stupid for not knowing this, but a coworker asked so I am asking here: I have written a python algorithm that solves his problem. given x > 0 add all numbers together from 1 to x.

def fac(x):
  if x > 0:
    return x + fac(x - 1)
  else:
    return 0

fac(10)
55

first what is this type of equation is this and what is the correct way to get this answer as it is clearly easier using some other method?

© Stack Overflow or respective owner

Related posts about math

Related posts about python