find sum of n numbers in python code example
Example 1: sum of any numbers in python
sum(list(map(int,input().split())))
Example 2: sum of n natural numbers in python
# 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)