Source Code :
n=int(input("Enter the no of elemnets in the list"))
b=[]
for i in range(0,n):
a=int(input("Elements :"))
b.append(a)
sum1=0
sum2=0
sum3=0
for j in b :
if(j>0):
if(j%2==0):
sum1=sum1+j
else :
sum2=sum2 + j
else :
sum3=sum3+j
print("Sum of all positive even no :",sum1)
print("Sum of all positive odd no ",sum2)
print("Sum of all negative no", sum3)
Output :
Enter the no of elements in the list 7
Elements :1
Elements :4
Elements :-6
Elements : -1
Elements : 8
Elements : 1
Elements :9
Sum of all positive even no : 12
Sum of all positive odd no 11
Sum of all negative no -7
n=int(input("Enter the no of elemnets in the list"))
b=[]
for i in range(0,n):
a=int(input("Elements :"))
b.append(a)
sum1=0
sum2=0
sum3=0
for j in b :
if(j>0):
if(j%2==0):
sum1=sum1+j
else :
sum2=sum2 + j
else :
sum3=sum3+j
print("Sum of all positive even no :",sum1)
print("Sum of all positive odd no ",sum2)
print("Sum of all negative no", sum3)
Output :
Enter the no of elements in the list 7
Elements :1
Elements :4
Elements :-6
Elements : -1
Elements : 8
Elements : 1
Elements :9
Sum of all positive even no : 12
Sum of all positive odd no 11
Sum of all negative no -7
No comments:
Post a Comment