CBSE Class 11 Informatics Practices Question 61 of 80

Lists in Python — Question 24

Back to all questions
24
Question

Question 19

Write a program that accepts elements of a list S and adds all the odd values and displays the sum.

Solution
S = eval(input("Enter list: "))

sum_odd = 0
for num in S:
    if num % 2 != 0:
        sum_odd += num

print("The sum of all odd values in the list is: ", sum_odd)
Output
Enter list: [43, 23, 5, 6, 8, 10, 12]
The sum of all odd values in the list is:  71
Answer