Skip to content
Snippets Groups Projects
homework_hints_hints_stripped.py 787 B
Newer Older
  • Learn to ignore specific revisions
  • tuhe's avatar
    tuhe committed
    # example_hints/instructor/cs106/homework_hints.py
    def find_primes(n): #!f 
        """
        Return a list of all primes up to (and including) n
        Hints:
            * Remember to return a *list* (and not a tuple or numpy ndarray)
            * Remember to include n if n is a prime
            * The first few primes are 2, 3, 5, ...
        """
        primes = [p for p in range(2, n+1) if is_prime(n) ]
        return primes
    
    def is_prime(n): #!f
        """
        Return true iff n is a prime
        Hints:
            * A number is a prime if it has no divisors
            * You can check if k divides n using the modulo-operator. I.e. n % k == True if k divides n.
        """
        for k in range(2, n):
            if k % n == 0: # This line is intentionally buggy so that we see the hint!
                return False
        return True