7.1.9 Diving Contest

Question: 8.1 What will the following code display?

numbers = [1, 2, 3, 4, 5]

numbers[2] = 99

print(numbers)

Answer: [1, 2, 99, 4, 5]

Question: 8.2 What will the following code display?

numbers = list(range(3))

print(numbers)

Answer: [0, 1, 2]

Question: 8.3 What will the following code display?

numbers = [10] * 5

print(numbers)

Answer: [10, 10, 10, 10, 10]

Question: 8.4 What will the following code display?

numbers = list(range(1, 10, 2))

for n in numbers:

print(n)

Answer: 1

3

5

7

9

Question: 8.5 What will the following code display?

numbers = [1, 2, 3, 4, 5]

print(numbers[-2])

Answer: 4

Donation Page

Support Our Work

Do you appreciate the value this website provides? If so, please consider donating to help keep it running. Your donation will go a long way in helping us continue to provide the same quality of content and services. Every bit helps, and your support is greatly appreciated. Thank you for your generosity.