Functions

← Back to assignments

ungraded
# Google is encouraged. Type what you find, do not paste it. # ---- Part 1: defining ---- def is_even(n): """Return True when n is even, False otherwise. is_even(4) → True is_even(7) → False Search: "python modulo even number". """ raise NotImplementedError def bigger(a, b): """Return the larger of two numbers. bigger(3, 7) → 7 bigger(9, 2) → 9 bigger(4, 4) → 4 Search: "python if else compare numbers". """ raise NotImplementedError # ---- Part 2: reusing ---- def same_parity(a, b): """Return True when both numbers are even or both are odd, reusing is_even. same_parity(2, 4) → True same_parity(2, 5) → False Search: "python boolean return". """ raise NotImplementedError def count_evens(numbers): """Return how many even numbers are in the list, reusing your is_even. count_evens([1, 2, 3, 4]) → 2 count_evens([1, 3]) → 0 Search: "python call function inside loop". """ raise NotImplementedError