Write a python function that returns the sum of n natural numbers


Topic: Write a python function that returns the sum of n natural numbers

Solution

def sum_natural(num):
    if num < 0:
       print("Please enter a positive number!")
    else:
       sum = 0
       while(num > 0):
           sum += num
           num -= 1
       return num



List all Python Programs