Informatics Practices

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

Python List Manipulation

4 Likes

Answer

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

Answered By

2 Likes


Related Questions