# First function: def independent(list_a, list_b): ''' We can say that two lists are independent if no value occupies the same position in both lists. Independent lists are not required to have the same length. For example, [1,2] and [2,1,3] are independent, and [1,2,3] and [4,2,'a'] are not independent. Parameters: list_a and list_b must be lists Returns True if list_a and list_b are independent, and returns False if they are not ''' if type(list_a) is not list or type(list_b) is not list: return False else: min_length = min(len(list_a), len(list_b)) for i in range(min_length): if list_a[i] == list_b[i]: return False return True # Second function: def primes_up_to_n(n): '''parameter : n - integer returns a list of all primes <= n returns None if n is not an integer ''' if type(n) is not int: return None else: list_of_primes = [] for potential_prime in range(2,n+1): #print("potential prime",potential_prime) could_be_prime = True done = False possible_divisor = 2 while could_be_prime and possible_divisor < potential_prime: #print("\tpossible divisor",possible_divisor) if potential_prime % possible_divisor == 0: could_be_prime = False is_prime = False else: possible_divisor += 1 if possible_divisor == potential_prime: list_of_primes.append(potential_prime) return list_of_primes # Third function: def binary_string(n): '''parameter: n - integer returns a string of "0"s and "1"s giving the binary representation of n returns None if n is not an integer ''' if type(n) is not int: return None else: if n == 0: return '0' else: negative = (n < 0) n = abs(n) bin_string = '' while n != 0: if n % 2 == 1: bin_string = '1' + bin_string else: bin_string = '0' + bin_string n = n // 2 if negative: bin_string = '-' + bin_string return bin_string