Lists and Loops

There are two ways to loop over a list. The first way uses the in keyword, which can be used to check if a particular value is in a list, or to loop over the elements one at a time:
numbers = [6, 8, 2, 9, 7]

print(6 in numbers) # True
print(0 in numbers) # False

for number in numbers:
  print(number)
# prints 6, 8, 2, 9, 7
The second way uses the range and len functions to loop over the list indexes, which is needed when changing the values in a list:
numbers = [6, 8, 2, 9, 7]

for i in range(len(numbers)):
  numbers[i] = numbers[i] ** 2

print(numbers)
# [36, 64, 4, 81, 49]

Exercise 1 of 6

Write a condition to check if a list called numbers contains the number 5.

Your code

Exercise 2 of 6

Write a condition to check if a list called names contains the value "Jude".

Your code

Exercise 3 of 6

Write the start of the loop to iterate over the list of numbers.
numbers = [1, 2, 3, 4, 5, 6]
# start of loop here
  print(number / 2)

Your code

Exercise 4 of 6

Say hello to each person in the list.
names = ["James", "Nicole", "Helen", "Troy"]

Your code

Exercise 5 of 6

Write the start of the loop to replace each element in the list with a number twice its size.
numbers = [1, 2, 3, 4, 5]
# start of loop here
  numbers[i] = numbers[i] * 2
print(numbers)

Your code

Exercise 6 of 6

Replace each name with the first name in the list, and print out the list.
names = ["James", "Nicole", "Helen", "Troy"]

Your code