CBSE Class 11 Computer Science Question 61 of 82

Lists in Python — Question 26

Back to all questions
26
Question

Question 21

WAP that takes an array S as an argument and add all the odd values and display the sum.

Solution
S = eval(input("Enter the array: "))
total = 0
for value in S:
    if value % 2 != 0:
        total += value
print("Sum of odd values:", total)
Output
Enter the array: [2, 4, 3, 9, 11, 5, 7, 8]
Sum of odd values: 35
Answer