Exercises
Add Items
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Add Grace and Katherine to the list so it ends up with three names.
Python
names = ["Ada"]
# add the other two
print(names)append adds one item; extend adds each item from an iterable.
names = ["Ada"]
names.extend(["Grace", "Katherine"])
print(names)Exercise 2Passed
Put Grace between Ada and Katherine using insert.
Python
names = ["Ada", "Katherine"]
# insert Grace in the middle
print(names)insert takes the position first, then the item.
names = ["Ada", "Katherine"]
names.insert(1, "Grace")
print(names)Exercise 3Passed
This throws the list away. Fix it so names ends up with both items.
Python
names = ["Ada"]
names = names.append("Grace")
print(names)append returns None. Call it for its effect and do not assign.
names = ["Ada"]
names.append("Grace")
print(names)