Python Program to find Sum of Natural Numbers

# Python program to find sum of n natural numbers
# take input
num = int(input('Enter a number: '))
# find sum of natural number
sum = 0
x = 1
while x <= num:
 sum += x
 x += 1
# display result
print('The sum of natural number =', sum)

OUTPUT:

Enter a number: 5
The sum of natural number = 15
Enter a number: 10
The sum of natural number = 55

Leave a Comment