Q. Write a Python script to print sum of negative numbers, sum of positive even numbers, sum of positive odd numbers from a list of numbers entered by the user. The script should end when the number entered is zero.


Answer =


sumneg = 0
sumposodd = 0
sumposeven = 0
while True :
    num = int (input("Enter the number :- "))
    if num == 0 :
        break
    elif num > 0 and num % 2 == 0 :
        sumposeven += num
    elif num > 0 and num % 2 != 0 :
        sumposodd += num
    else :
        sumneg += num
print ("Sum of even positive number :- ", sumposeven)
print ("Sum of odd positive number :- ", sumposodd)
print ("Sum of negative number :- ", sumneg)

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post