wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz #1

Total questions: 22

Worksheet time: 13mins

Name
Class
Date
1.

Question : What is the result of the following Python expression?

a)

A) 11

b)

B) 16

c)

C) 10

d)

D) 26

2.

Question : Which of the following data types is used to store whole numbers in Python?

a)

A) Float

b)

B) String

c)

C) Integer

d)

D) Boolean

3.

Question : Which loop is typically used when you know in advance how many times you want to repeat a piece of code?

a)

A) For loop

b)

B) While loop

c)

C) Do-While loop

d)

D) Repeat-Until loop

4.

Question : What will the following code print?

a)

A) 0 1 2 3 4

b)

B) 1 2 3 4 5

c)

C) 0 1 2 3

d)

D) 1 2 3 4

5.

Question : In Python, what keyword is used to start an if-else statement?

a)

A) elif

b)

B) else

c)

C) then

d)

D) case

6.

Question : Which of the following is not a valid variable name in Python?


a)

A) my_variable

b)

B) 123variable

c)

C) _underscore

d)

D) myVariable

7.

What does the random.randint(1, 10) function do in Python?

a)

A) Generates a random float between 1 and 10

b)

B) Generates a random integer between 1 and 9

c)

C) Generates a random integer between 1 and 10

d)

D) Generates a random integer between 2 and 10

8.

Question : Which of the following is used to define a function in Python?


a)

A) begin

b)

B) func

c)

C) function

d)

D) def

9.

Question : What is the output of the following code?


a)

A) "Hello" printed 5 times

b)

B) "Hello" printed 4 times

c)

C) "Hello" printed 6 times

d)

D) "Hello" printed 1 time

10.

Question : What is the primary purpose of a for loop in Python?


a)

A) To execute a block of code repeatedly until a condition is met

b)

B) To loop through a sequence (e.g., list or range) and execute code for each element

c)

C) To create a conditional branch in the code

d)

D) To define a reusable function

11.

Question : Which of the following is not a comparison operator in Python?


a)

A) ==

b)

B) !=

c)

C) =

d)

D) <=

12.

Question : What is the correct syntax for a multiline comment in Python?


a)

A) /* This is a comment */

b)

B) # This is a comment

c)

C) <!-- This is a comment -->

d)

D) ''' This is a comment '''

13.

Question : In Python, what does the len() function do?


a)

A) Returns the largest element in a list.

b)

B) Returns the smallest element in a list.

c)

C) Returns the total number of elements in a list or the length of a string.

d)

D) Returns the sum of elements in a list.

14.

Question : What is the output of the following code?


a)

A) "apple",

"banana",

"cherry"

b)

B) "apple" "banana" "cherry"

c)

C) "apple\banana\cherry"

d)

D) apple

banana

cherry

15.

Question : What is the purpose of the following code?


a)

A) It asks the user for a number and repeats until the user enters 'q'.

b)

B) It continuously prints "Enter a number (or 'q' to quit): ".

c)

C) It keeps asking for a number even after the user enters 'q'.

d)

D) It prints "You entered: {user_input}" for any user input.

16.

Question : What is the result of the following code?

a)

A) 3

b)

B) 2

c)

C) (1, 2, 3, 4, 5)

d)

D) Error: Tuples do not support indexing

17.

Question : Explain what the following code does:



(a)  

18.

Question : Describe the purpose of this code:

(a)  

19.

Question: Explain the functionality of the following code:

(a)  

20.

What does this code do?

a)

A) It asks the user for two numbers and prints their sum.

b)

B) It defines two variables, adds them, and prints the result.

c)

D) It calculates the product of two numbers.

d)

C) It prints the numbers 5 and 10.

21.

Question: What is the purpose of this code?

a)

A. Validates a user's password

b)

B. Prints "Access granted!" infinitely

c)

C. Prints "Access denied." only once

d)

D. Prints "Access denied." until the user enters "secret"

22.

Question: How do you feel about what you're learning and how it's being taught?

a)

A) I really like it and I'm excited.

b)

B) I kind of like it, but I'm not super excited.

c)

C) I don't feel strongly one way or the other.

d)

D) I don't like it at all, and I'm not interested.