No student devices needed. Know more
17 questions
In programming, what is iteration/looping?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
numbers = [5, 14 ,9, 17]
for number in numbers:
if number >= 9:
print (number)
The output will be?
17
9
14
9
17
14
17
Which of the following programs prints ten lines?
for i in range(10):
print("hi")
for i = 1 to 10:
print("hi")
for i in 1 - 10:
print("hi")
for i from 0 to 9:
print("hi")
Which of the following best describes the purpose of a for loop?
A for loop is for doing something an indeterminate number of times.
A for loop is doing something an infinite number of times.
A for loop is for doing something a fixed number of times.
A for loop is for doing something three times.
Which of the following for loops would print the following numbers?
3
5
7
9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What is the value of num when this loop completes?
num = 0
for i in range(2, 8, 2):
num += i
2
8
12
20
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
What would be the output of the following code:
for i in range(3):
print(i)
1 2 3
i i i i
i i i
0 1 2
drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:
print(drink)
"coffee"
["coffee", "tea", "water", "juice", "soda"]
drink
"coffee tea water juice soda"
What would be the output of the following code:
for i in range(3):
print(5)
0 1 2
3 3 3 3 3
5 5 5
0 1 2 3 4
numbers = [2, 4, 6, 8]
for number in numbers:
print("hello!")
2 hello! 4 hello! 6 hello! 8 hello!
hello!
2 4 6 8
hello! hello! hello! hello!
Explore all questions with a free account