I’m practicing functions and I’m working on using recursion to find the sum of a sequence of numbers.
I’ve got two codes:
The first one I wrote and the second is the answer on the website I’m using to practice.
Which one is faster (or is this negligible as they both use recursion)? I was the second one is faster because of extra computing power of the input() function.
def recurs(num):
if num == 0:
return num
else: return num + recurs(num-1)
num = int(input("Enter number "))
print(recurs(num))
def addition(num):
if num:
return num + addition(num - 1)
else:
return 0
res = addition(10)
print(res)