[Solved] Python code for adding all even numbers and odd numbers separately and displaying into separate totals


This way you can get a list of numbers from 0 to 20

x = range(0,20)

This way you filter even numbers

even = filter(lambda x : x % 2 == 0, x)

This way you sum all the evens

x = reduce(lambda x, y : x + y, even, 0)

Do the proper thing for odd numbers 😉

As you are new to Python, let me suggest you to read the Built-in functions page in Python reference manual to find some funny functions to do these kind of things.

1

solved Python code for adding all even numbers and odd numbers separately and displaying into separate totals