Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created August 30, 2021 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamelafox/591315b87e520ad0609ed0c64b65a59a to your computer and use it in GitHub Desktop.
Save pamelafox/591315b87e520ad0609ed0c64b65a59a to your computer and use it in GitHub Desktop.
Prime Factors
def is_prime(n):
"""Return True iff N is prime.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(8)
False
>>> is_prime(21)
False
>>> is_prime(23)
True
"""
return n > 1 and smallest_factor(n) == n
def smallest_factor(n):
"""Returns the smallest value k>1 that evenly divides N."""
pass
def print_factors(n):
"""Print the prime factors of N.
>>> print_factors(180)
2
2
3
3
5
"""
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment