Created
August 15, 2021 17:00
-
-
Save onelharrison/f6150727cc6e17131e425d940df38473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from math import floor, sqrt | |
| def is_even(num: int) -> bool: | |
| """Returns True if a given number is even, otherwise False""" | |
| return num % 2 == 0 | |
| def is_prime(num: int) -> bool: | |
| """Returns True if a given number is prime, otherwise False""" | |
| if num <= 1: | |
| return False | |
| for factor in range(2, floor(sqrt(num) + 1)): | |
| if num % factor == 0: | |
| return False | |
| return True | |
| nums = range(1, 10) | |
| evens = list(filter(is_even, nums)) | |
| primes = list(filter(is_prime, nums)) | |
| print(evens) # [2, 4, 6, 8] | |
| print(primes) # [2, 3, 5, 7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment