Write a program in Python to calculate and display the sum of all odd numbers in the list
Answers
Answer:
In this python program to find Sum of Even and Odd Numbers in a List, User entered items = [2, 3, 4, 5], Even_Sum = 0, Odd_Sum = 0. if(NumList[1] % 2 == 0) => if(3 % 2 == 0) – Condition is False, so it enters into the Else block. if(5 % 2 == 0) – Condition is False, so it enters into Else block
Explanation:
plz rate me brainliest
#Python program to find sum of odd and even numbers in a list
NumList=[] #empty list
evenSum=0 #declare and initialised variable evenSum to sum of even numbers
oddSum=0 #declare and initialised variable oddSum to sum of odd numbers
Number=int(input("Please enter the total number of list elements: "))
for i in range(1, Number+1):
value=int(input("Please enter the value of %d Eleements: " %i))
NumList.append(value)
for j in range(Number):
if(NumList[j]%2==0):
evenSum=evenSum+NumList[j]
else:
oddSum=oddSum+NumList[j]
print("\n The sum of even numbers in the list= ",evenSum)
print("\n The sum of odd numbers in the list= ",oddSum)