Q:

Write a Python Program to Calculate sum of N natural number. N should be taken from the keyboard

0

Write a Python Program to Calculate sum of N natural number. N should be taken from the keyboard

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# Sum of natural numbers up to num
N = float(input('enter natural number: '))

if N < 0:
   print("this number is not natural, natural number should be a positive number")
else:
   sum = 0
   # use while loop to iterate until zero
   while(N > 0):
       sum += N #same as sum=sum+N
       N -= 1
   print("The sum is", sum)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now