Showing posts with label Python program to find the sum of natural numbers.. Show all posts
Showing posts with label Python program to find the sum of natural numbers.. Show all posts

Friday, November 15, 2019

Python program to find the sum of natural numbers.

# Sum of natural numbers up to num
num = 16
if num < 0:
   print("Enter a positive number")
else:
   sum = 0
   # use while loop to iterate until zero
   while(num > 0):
       sum += num
       num -= 1
   print("The sum is", sum)