def recur_sum(n): 
      """Function to return the sum
      of natural numbers using recursion"""
      if n <= 1:
              return n
      else:
              return n + recur_sum(n-1)
num = int("16")

if num < 0:
      print("Enter a positive number")
else:
      print("The sum is ",recur_sum(num))
Вывод результата 16:
 ('The sum is ', 136) 

Оценка - 1.0 (9)

 Похожие публикации
2015-11-29 • Просмотров [ 5134 ]