Test your understanding of iterating over lists and strings.
Passing Score: 6 / 10
Attempts: Unlimited
1Which is the correct syntax to loop through each element in a list called `my_data`?
for item in my_data:
loop item over my_data:
for my_data get item:
while item in my_data:
2In the loop `for value in numbers:`, what does the variable `value` represent during each iteration?
3How would you iterate through each character in a string variable called `message`?
for i in range(len(message)):
for char in message:
iterate char over message:
while message has chars:
4Consider the code: `word = "Py"; for letter in word: print(letter)`. What is the output?
5You have a list `scores = [88, 92, 100]`. Which loop prints each score on a new line?
print(scores)
for s in scores: print(s)
for i in range(scores): print(i)
print(scores[0], scores[1], scores[2])
6What is the primary purpose of a `for item in sequence:` loop?
7In the statement `for char in "Hello":`, what part is the "iterable"?
for
char
"Hello"
:
8Can you use a `for item in sequence:` loop to iterate over the elements of a tuple? (e.g., `my_tuple = (1, 2, 3)`)
9What is an advantage of using `for element in data:` compared to using `for i in range(len(data)): print(data[i])` for simple iteration?
10The concept of using a `for` loop to process each item without needing to know *how* the items are stored (e.g., index numbers) is an example of which Computational Thinking principle?
Your Score: 0 / 10
You have already successfully completed the knowledge check for this module.