Font size
WorksheetsUnderstanding Input, Selection and Loops in Python
Total questions: 25
Worksheet time: 14mins
What does the input() function do in Python?
It prints text to the screen.
It receives input from the user.
It saves data to a file.
It creates a loop.
Which of the following is an example of output in Python?
input("Enter your name: ")
print("Hello, world!")
len("cat")
int("5")
Which of the following best describes a loop in Python?
A way to store data
A way to repeat a block of code multiple times
A way to print output
A way to define a function
What is the main purpose of statements such as if, elif, and else in Python?
To store information
To decide which code to run based on conditions
To repeat code
To receive input
Which of the following is the correct way to check the length of a string in Python?
size("hello")
count("hello")
len("hello")
length("hello")
What does the break statement do in a loop?
It skips the current iteration.
It ends the loop immediately.
It starts the loop over.
It prints a message.
Which of the following is an example of a while loop in Python?
while True:
print("Hello")
This is a for loop.
This is a while loop.
This is an if statement.
This is a function.
How can you convert a string input to an integer in Python?
str("5")
int("5")
float("5")
input("5")
Which of the following is a selection statement in Python?
if
input
len
What does the following code do?
if len(word) < 3:
print("Short")
elif len(word) < 7:
print("Medium")
else:
print("Long")
It checks the number of words in a sentence.
It checks the length of a string and prints a message based on its length.
It prints the word backwards.
It counts the number of vowels.
What is the result of len("Python")?
5
6
7
0
Which of the following statements about loops is true?
Loops can only run a fixed number of times.
Loops can run until a certain condition is met.
Loops cannot be stopped early.
Loops are only used for printing.
What will be the output of the following Python code?
temp = 10
if temp < 0:
print("Freezing")
elif temp < 20:
print("Cool")
else:
print("Warm")
Freezing
Cool
Warm
Nothing
Which of the following is the correct way to use an elif statement in Python?
elif condition:
elseif condition:
else if condition:
ifelse condition:
What is the purpose of the following code?
while True:
user_input = input("Enter something: ")
if user_input == "stop":
break
To print "stop" repeatedly
To keep asking for input until the user types "stop"
To count the number of inputs
To convert input to uppercase
Which of the following is NOT a valid selection statement in Python?
if
elif
else
What will be the output of the following code if the user enters 25?
temp = int(input("Enter temperature in Celsius: "))
if temp < 0:
print("Freezing")
elif temp < 20:
print("Cool")
else:
print("Warm")
Freezing
Cool
Warm
Nothing
Which function would you use to determine the number of characters in the string "Great Britain"?
count("Great Britain")
len("Great Britain")
size("Great Britain")
length("Great Britain")
Which function is used to show something on screen as output? Use just the keyword, without brackets
(a)
Which function is used to communicate with the program while running, writing something using the keyboard? Put the keyword without brackets
(a)
What is the correct order of the following?
if
elif
else
if
elif
else
elif
if
else
elif
else
if
Which symbols can you use to check if something is equal to something else?
Be careful when typing the answer!
(a)
What is a * ?
What is a / ?
