U
U
Uoleran2019-03-16 16:04:17
Python
Uoleran, 2019-03-16 16:04:17

Recursion in Python. A simple example. What's wrong?

I do a function by the factorial of a given number

a=1
def fun(x):
  if x<=0:
    pass
  else:	
    x-=1
    global a
    a*=x
    return fun(x)
print(fun(5))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-03-16
@Vlad_IT

Why do you need a pass? Why don't you collect the result of recursions, but return the last one (which will return nothing, because it will end its work on pass?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question