#!/usr/bin/env python3 # An example of implementing integer factorisation in Python: find all prime numbers that divide a given number # prime number test def isPrime(n): """Test whether the given number @n@ is a prime number.""" # +++your code here+++ # build a list of all prime numbers, to be used later # use a list comprehension! primes = # +++your code here+++ # main fct for first exercise: integer factorisation def factor(m): """For a given integer number @n@, find all prime numbers that divide it.""" # +++your code here+++ # additional function for second exercise: turn a list with repeated entries into a list of pairs of (value, # of occurences) def cleanup2(xs): # +++your code here+++ # Simple provided test() function used in main() to print # what each function returns vs. what it's supposed to return. def test(got, expected): if got == expected: prefix = ' OK ' else: prefix = ' ** ' print('%s got: %s expected: %s' % (prefix, repr(got), repr(expected))) if __name__ == '__main__': print("Integer factorisation:") test(factor(120),[2, 2, 2,3, 5]) test(cleanup2(factor(120)), [(2, 3), (3, 1), (5, 1)])