Chapters
Python114 chapters

Exercises

List Access

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Print the first and the last name, without hard-coding the length.

Python
names = ["Ada", "Grace", "Katherine"]
# print the first, then the last
Exercise 2

Print the middle three numbers using a slice.

Python
numbers = [0, 1, 2, 3, 4, 5]
# print [1, 2, 3]
Exercise 3

Take a slice of the first two items, change its first item to 99, and show the original is untouched.

Python
original = [1, 2, 3]
# slice, change the slice, print the slice then the original