Write a function called evens()
that will output all the even numbers in list.
The function will receive a Python list
passed in as a parameter. It should display the output to the screen.
Examples:
evens( [1, 2, 3, 4, 5] )
displays 2 4
evens( [1, 3, 5] )
displays nothingevens( range(10) )
displays 0 2 4 6 8
For +20 bonus points, instead of print
ing the even numbers, the function must return a new list containing only the even numbers. Then you will print them in main()
.
Bonus Examples:
evens( [1, 2, 3, 4, 5] )
returns the list [2, 4]
evens( [1, 3, 5] )
returns the empty list []
evens( range(10) )
returns the list [0, 2, 4, 6, 8]
©2017 Graham Mitchell