Python code for sum of all even numbers and product of all odd numbers in the entered list
Answers
Answered by
5
First of all, we will need to take an input from the user with all the numbers.
numbers = list(map(int,input('Enter numbers separated by a comma:').split(',')))
Now, we have all the numbers stored in a list called number. We will need to check whether a number is even or odd and then find the total sum.
- Identify whether the number is odd or even, add them to a specified list and the find the sum.
CODE:
numbers = list(map(int,input('Enter numbers separated by a comma:').split(',')))
even,odd = [x for x in numbers if x%2 == 0],[x for x in numbers if x%2 != 0]
print(f'Sum of even numbers is {sum(even)}\nSum of odd numbers is {sum(odd)}')
Similar questions