Font size
WorksheetsPython For Loops
Total questions: 33
Worksheet time: 1hrs 6mins
What is the syntax of a for loop in Python?
for item in iterable: # code to be executed
for item in iterable: # code to be executed
for element in list: # code to be executed
for i in range(n): # code to be executed
How do you use the range() function in a for loop?
Specify only the step value within the range() function.
Specify the start, stop, and step values within the range() function.
Specify only the stop value within the range() function.
Specify only the start value within the range() function.
What is the output of the following code? for i in range(5): print(i)
0 1 2 3 4
0 1 2 3 5
1 2 3 4 5
0 1 2 3 6
What is the output of the following code? for i in range(1, 6): print(i)
1 2 3 4 5
1 2 3 4
1 2 3 4 6
1 2 3 4 6 7
What is the output of the following code? for i in range(1, 10, 2): print(i)
1 3 5 7
2 4 6 8
0 2 4 6 8
1 3 5 7 9
What is the output of the following code? for i in range(10, 1, -1): print(i)
1
10 9 8 7 6 5 4 3 2
11
0
How do you iterate over a list using a for loop?
for i in range(len(my_list)):
for item in range(my_list):
for item in my_list()
for item in my_list:
What is the output of the following code? fruits = ['apple', 'banana', 'cherry'] for fruit in fruits: print(fruit)
The output of the code is: apple banana cherry
cherry, apple, banana
orange, banana, apple
apple, banana, orange
How do you iterate over a string using a for loop?
for char in string:
for char in string():
for char in range(string):
for i in range(len(string)):
What is the output of the following code? for char in 'Hello': print(char)
H l l o
H l l o
H e l l o
H e l l o
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
A condition is
a statement that is either True or False
a string
an integer
a list
Which kind of loop would be used?
I need a program that will keep letting me add a monthly payment for 12 months.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a revision program that will run through revision questions 4 times.
FOR Loop
WHILE Loop
What is a variable?
a type of graphics
A box(memory location) where you store values
Data type
a type of memory
What symbol is used in python to assign values to a variable?
equals =
plus +
minus -
asterisk *
What will be the output?
name = "Dave"
print (name)
(name)
Dave
name
Nothing
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
True
False
Which statement correctly assigns the string "Tanner" to the variable name?
name = print( "Tanner")
input("Tanner")
name= "Tanner"
name = input("Tanner")
What will be the output?
name = "Dave"
print ("name")
Dave
name
"name"
"Dave"
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
Choose the correct output of the following code.
for i in range(10,15):
print(i)
10
11
12
13
14
15
10
11
12
13
14
11
12
13
14
15
11
12
13
14
What symbol do you use to make a comment in Python?
+
//
$
#
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
Function range(3) is equivalent to "
range(1,3)
range(0,3)
range(0,3,1)
range(1,3,0)
Which of the following function is used in python for loop to specify the initial, final and increment values?
range
format
input
In Python, what are if-statements used for?
Looping
Indexing
Decision Making
Testing
What is the output of this code?
click = True
Like = 0
if click:
Like = Like + 1
print(Like)
0
1
2
3
What is the output of the following code?
What is the output of following code
Temperature = 20
Thermo = 15
if Temperature < 15:
Thermo = Thermo + 5
print(Thermo)
20
15
25
10
What is the output of the following code?
Time = "Day"
Sleepy = False
Pajamas = "Off"
if Time == "Night" and Sleepy == True:
Pajamas = "On"
print(Pajamas)
off
on
False
Day
What will the be the output of the following code?
if (10<0) and (0 <-10):
print(“A”)
else:
print(“B”)
A
B
AB
BA
What is the output of the following code?
a = "b"
if True or True:
a = "a"
print(a * 2)
bb
aa
ab
ba
The result of this program:
Friday = False
if Friday:
print "Jeans day!"
else:
print "Uniform day"
Jeans day
Today is Friday
Uniform day
Not Friday
