Another Recursion problem

A recursion problem where I was asked to add all the numbers counting down from a given number then, I subtracted 5 from the total.

def addNums(number): if number == 1: return number - 5 else: return number + addNums(number-1) x = addNums(10) print (x)

Recursion Problems

The first 9 lines is a problem that adds up all of the numbers in a list using recursion. In lines 12 through 18, I used recursion to calculate the reciprocal of consecutive positive integers starting from 1.

def listNums(number): if len(number) == 1: return number[0] else: var = number[len(number)-1] number.pop() return var + listNums(number) x = listNums([3,4,8,9]) print(x) def harmonic(num): if num == 1: return num else: return 1/num + harmonic(num - 1) x = harmonic(5) print(x)