Module 3 · after
The same 6 questions you saw before the module. No running the code: predict, then compare with your first score.
def flip(items): if len(items) == 0: return [] return flip(items[1:]) + [items[0]] print(flip([1, 2, 3]))
needs = {'a': ['b', 'c'], 'b': ['d'], 'c': ['d', 'e'], 'd': [], 'e': []} def explore(item, visited, order): if item in visited: return visited.add(item) order.append(item) for before in needs[item]: explore(before, visited, order) order = [] explore('a', set(), order) print(order)
needs = {'cake': ['batter', 'oven'], 'batter': ['eggs', 'flour'], 'oven': [], 'eggs': [], 'flour': []} def topo_order(goal): order = [] visited = set() def build(item): if item not in visited: visited.add(item) for before in needs[item]: build(before) order.append(item) build(goal) return order print(topo_order('cake'))
def multiplications(rows, cols): count = 0 for r in range(rows): count += cols return count print(multiplications(8, 4) + multiplications(4, 8))
Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy