Python Program to Find Sum of 10 Numbers and Skip Negative Numbers

Write a Python program to find sum of 10 numbers and skip negative numbers. In this Python example, for loop range allows entering 10 numbers, and the if condition checks whether there are any negative numbers. If True, continue statement will skip that number from adding to posSum variable.

posSum = 0

print("Please Enter 10 Numbersto Find Positive Sum\n")
for i in range(1, 11):
    num = int(input("Number %d = " %i))

    if num < 0:
        continue

    posSum = posSum + num

print("The Sum of 10 Numbers by Skipping Negative Numbers = ", posSum)
Python Program to Find Sum of 10 Numbers and Skip Negative Numbers

This Python program finds the sum of 10 positive numbers and skips the negative numbers using a while loop.

posSum = 0

print("Please Enter 10 Numbersto Find Positive Sum\n")
i = 1
while(i <= 10):
    num = int(input("Number %d = " %i))

    if num < 0:
        i = i + 1
        continue

    posSum = posSum + num
    i = i + 1

print("The Sum of 10 Numbers by Skipping Negative Numbers = ", posSum)
Please Enter 10 Numbersto Find Positive Sum

Number 1 = 10
Number 2 = -12
Number 3 = 15
Number 4 = -24
Number 5 = 100
Number 6 = -90
Number 7 = 120
Number 8 = -34
Number 9 = 80
Number 10 = 70
The Sum of 10 Numbers by Skipping Negative Numbers =  395