num = int(input("Enter a number: "))
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate un till zero
while(num > 0):
sum += num
num -= 1
print("The sum is",sum)
This example shows the sum of the first 100 positive numbers (0-100)
This example shows the sum of the first 100 positive numbers (0-100)
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer