Font size
WorksheetsPython (I/O to Lists) Formative Quiz
Total questions: 25
Worksheet time: 9mins
What is the syntax for an if-else statement in Python?
if condition: # code block for else condition else: # code block for if condition
if condition: # code block for if condition else: # code block for else condition
if condition: # code block for if condition else: # code block for if condition
if condition: # code block for if condition else: # code block for else condition
When is the else block executed in an if-else statement?
When the condition in the if statement is false.
When the program encounters a break statement.
When the condition in the if statement is null.
When the condition in the if statement is true.
Which Python code checks if a number is even or odd, using a conditional statement?
num % 2 == 0
num / 2 == 0
num % 2 == 1
num % 2 != 0
What are the Boolean operators in Python?
and, or, not
if, else, while
true, false, maybe
plus, minus, multiply
What is the result of the Boolean expression: True AND False?
False
True
True AND True
False AND True
Explain the 'not' operator with an example in Python.
Example: not False returns True
Example: not 'hello' returns 'hello'
Example: not 1 returns 0
Example: not True returns False
How do you assign a value to a variable in Python?
assign variable_name = value
variable_name = value
value = variable_name
value to variable_name
What is the difference between '=' and '==' in Python?
'=' is for assigning, while '==' is for comparing
'=' is for comparing, while '==' is for assigning
'=' is for calculating, while '==' is for comparing
'=' is for calculating, while '==' is for assigning
Write a Python code to swap the values of two variables without using a temporary variable.
a, b = b, a
a = b, b = a
a = a + b
b = a - b
a = a - b
temp = a
a = b
b = temp
What is the syntax for a while loop in Python?
if condition:
# code to be executed
for condition:
# code to be executed
do condition:
# code to be executed
while condition:
# code to be executed
How is the condition checked in a while loop in Python?
By using a string expression
By using a list expression
By using a numeric expression
By using a boolean expression
Write a Python code to print numbers from 1 to 5 using a while loop.
while num <= 5: print(num) num += 1
print(1, 2, 3, 4, 5)
while num < 5: print(num)
for num in range(1, 6): print(num)
What is a list in Python?
A mathematical equation used in Python programming
A type of data structure used in Java programming
A collection of items that are ordered and changeable
A type of snake found in the Amazon rainforest
How do you access items in a list in Python?
myList[index]
myList<index>
myList(index)
myList{index}
Write a Python code to add an item to the end of a list.
my_list.extend(new_element)
my_list.add(new_element)
my_list.insert(new_element)
my_list.append(new_element)
What is the correct way to remove an item from a list in Python?
my_list.remove(item)
my_list.delete(item)
my_list.pop(item)
my_list.discard(item)
How do you iterate through a list in Python using a for loop?
for item in my_list:
for i in range(len(my_list)):
for item in range(my_list):
for i in my_list:
What is the result of the Boolean expression: False OR True?
True
False
False OR False
True OR False
Write a Python code to print the numbers from 1 to 5.
for i in range(5):
print(i)
for i in range(1, 6):
print(i)
for i in range(1, 5):
print(i)
for i in range(6):
print(i)
Explain the difference between 'break' and 'continue' statements in Python.
'break' is used to exit the loop, while 'continue' is used to skip the current iteration and continue with the next iteration.
'break' is used to skip the current iteration and continue with the next iteration, while 'continue' is used to exit the loop.
'break' is used to continue with the next iteration, while 'continue' is used to exit the loop.
Both 'break' and 'continue' are used to exit the loop
BONUS: Which 2023 movie had the highest box-office gross worldwide?
Barbie
Oppenheimer
The Super Mario Bros. Movie
Guardians of the Galaxy Vol. 3
BONUS!
BONUS: According to Spotify, who is the top artist of 2023, with 26.1 billion global streams?
Taylor Swift
Bad Bunny
The Weeknd
Drake
BONUS: Between these four YouTubers, who has the most subscribers?
MrBeast
Cocomelon
Kids Diana Show
PewDiePie
BONUS: Which video game currently has the most monthly active users (MAU) globally?
Fortnite
Minecraft
The Sims 4
Roblox
