recursion (sum of natural numbers)

Sai_kiran_rachakonda · June 14, 2022
def nat(n):
    if n < 0:
        return 0
    else:
        return n + nat(n - 1)

print(nat(5))
        
Output

Comments

Please sign up or log in to contribute to the discussion.