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
Write a program to create a list of elements. Input an element from the user that has to be inserted in the list. Also, input the position at which it is to be inserted.
Write a program to read elements of a list and do the following:
(a) The program should ask for the position of the element to be deleted from the list and delete the element at the desired position in the list.
(b) The program should ask for the value of the element to be deleted from the list and delete this value from the list.
Write a program to calculate the mean of a given list of numbers.
WAP in Python to delete all duplicate elements in a list.
For example,
If list is: [5, 2, 4, -5, 12, 2, 7, 4]
After deleting duplicate elements, new list should be: [5, 2, 4, -5, 12, 7]