Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

3. Find the sum of n natural numbers

 num = int(input('Enter a number: '))

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)

Post a Comment

0 Comments