wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Understanding Input, Selection and Loops in Python

Total questions: 25

Worksheet time: 14mins

Name
Class
Date
1.

What does the input() function do in Python?

a)

It prints text to the screen.

b)

It receives input from the user.

c)

It saves data to a file.

d)

It creates a loop.

2.

Which of the following is an example of output in Python?

a)

input("Enter your name: ")

b)

print("Hello, world!")

c)

len("cat")

d)

int("5")

3.

Which of the following best describes a loop in Python?

a)

A way to store data

b)

A way to repeat a block of code multiple times

c)

A way to print output

d)

A way to define a function

4.

What is the main purpose of statements such as if, elif, and else in Python?

a)

To store information

b)

To decide which code to run based on conditions

c)

To repeat code

d)

To receive input

5.

Which of the following is the correct way to check the length of a string in Python?

a)

size("hello")

b)

count("hello")

c)

len("hello")

d)

length("hello")

6.

What does the break statement do in a loop?

a)

It skips the current iteration.

b)

It ends the loop immediately.

c)

It starts the loop over.

d)

It prints a message.

7.

Which of the following is an example of a while loop in Python?

while True:
    print("Hello")

a)

This is a for loop.

b)

This is a while loop.

c)

This is an if statement.

d)

This is a function.

8.

How can you convert a string input to an integer in Python?

a)

str("5")

b)

int("5")

c)

float("5")

d)

input("5")

9.

Which of the following is a selection statement in Python?

a)

print

b)

if

c)

input

d)

len

10.

What does the following code do?

if len(word) < 3:
    print("Short")
elif len(word) < 7:
    print("Medium")
else:
    print("Long")

a)

It checks the number of words in a sentence.

b)

It checks the length of a string and prints a message based on its length.

c)

It prints the word backwards.

d)

It counts the number of vowels.

11.

What is the result of len("Python")?

a)

5

b)

6

c)

7

d)

0

12.

Which of the following statements about loops is true?

a)

Loops can only run a fixed number of times.

b)

Loops can run until a certain condition is met.

c)

Loops cannot be stopped early.

d)

Loops are only used for printing.

13.

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")

a)

Freezing

b)

Cool

c)

Warm

d)

Nothing

14.

Which of the following is the correct way to use an elif statement in Python?

a)

elif condition:

b)

elseif condition:

c)

else if condition:

d)

ifelse condition:

15.

What is the purpose of the following code?

while True:
    user_input = input("Enter something: ")
    if user_input == "stop":
        break

a)

To print "stop" repeatedly

b)

To keep asking for input until the user types "stop"

c)

To count the number of inputs

d)

To convert input to uppercase

16.

Which of the following is NOT a valid selection statement in Python?

a)

if

b)

elif

c)

else

d)

print

17.

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")

a)

Freezing

b)

Cool

c)

Warm

d)

Nothing

18.

Which function would you use to determine the number of characters in the string "Great Britain"?

a)

count("Great Britain")

b)

len("Great Britain")

c)

size("Great Britain")

d)

length("Great Britain")

19.

Which function is used to show something on screen as output? Use just the keyword, without brackets

(a)  

20.

Which function is used to communicate with the program while running, writing something using the keyboard? Put the keyword without brackets

(a)  

21.

What is the correct order of the following?

a)

if

elif

else

b)

if

elif

else

elif

c)

if

else

elif

d)

else

if

22.

Which symbols can you use to check if something is equal to something else?

Be careful when typing the answer!

(a)  

23.
The correct way to write a variable in Python?
a)
my_variable = 10
b)
my variable = 10
c)
my_variable is 10
d)
my_variable: 10
24.
Arithmetic Operator
What is a * ?
a)
Addition
b)
Subtraction
c)
Multiplication
d)
Modulo
25.
Arithmetic Operators
What is a / ? 
a)
Addition
b)
Subtraction
c)
Division
d)
Modulo