Why does `for n in L1` make `L2[n]` meaningless, and what does looping over `range(len(L1))` fix?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Two same-length lists arrive side by side: ages = [2, 5, 1] and names = ["blobfish", "crazyant", "parafox"]. Build one pair per position, in order, each holding the name first and the age second — so the pair at index 0 is ("blobfish", 2).
Assign the finished list of three tuples to pairs. Walk the positions, not the elements. (len() gives a list's length, range() turns a length into the positions, and lists grow with .append().)
Indexing two parallel lists with range(len(L1))
Record that for n in L1 yields elements, so L2[n] is meaningless, and write for i in range(len(L1)), where i takes the values 0, 1 and 2 and indexes both lists.
Constructing an object then naming it
Write a = Animal(L1[i]), which sets the age and leaves the name None, followed by a.set_name(L2[i]) through the setter rather than an assignment to a.name.
The accumulator with the test loop outside
Write the finished make_animals with L = [], L.append(a) and return L for L1 = [2,5,1] and L2 = ["blobfish", "crazyant", "parafox"], placing for i in animals: print(i) in the calling code.