Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

Sum of postive numbers in python

Python program to get input n and n positive integers (skip the negative number), then compute the sum of positive integers

Sample Input 1:

5 6 7 2 -8 1 8

Sample Output 1:


Program or Solution

num=int(input("Enter number:"))
    num=int(input("Enter number:"))



Program Explanation

since 1 is always true, input() statement gets input from user continously, if user enters a negative number it exit from while loop using break statement.