Menu Close

Sum of Odd, Even and Negative numbers

Write a program to find the sum of odd numbers, even numbers and negative numbers.

tot=int(input("Enter the N number: "))
list1=[]
for i in range(tot):
  d=int(input())
  list1.append(d)

odd=0
eve=0
neg=0

for i in range(tot):
  if list1[i]%2==0 and list1[i]>0:
    eve=eve+list1[i]
  elif list1[i]%2!=0 and list1[i]>0:
    odd=odd+list1[i]
  if list1[i]<0:
    neg=neg+list1[i]

print("Sum of positive even numbers: {}".format(eve))
print("Sum of positive odd numbers: {}".format(odd))
print("Sum of negative numbers: {}".format(neg))

Exec. on linux

Morae!Q!