wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Basics Quiz for Grade 10

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the output of the following Python code snippet? ```python print("Hello, World!"[7]) ```

a)

H

b)

W

c)

o

d)

,

2.

Which of the following is a valid way to declare an integer variable in Python?

a)

`int number = 5`

b)

`number = 5`

c)

`integer number = 5`

d)

`num = "5"`

3.

What will be the output of the following code? ```python import random print(random.randint(1, 10)) ```

a)

A random integer between 1 and 10, inclusive

b)

A random integer between 1 and 9, inclusive

c)

A random float between 1 and 10

d)

A random float between 0 and 1

4.

Consider the following list: `fruits = ["apple", "banana", "cherry"]`. What is the result of `fruits[1]`?

a)

apple

b)

banana

c)

cherry

d)

None

5.

What is the purpose of a for loop in Python?

a)

To execute a block of code once

b)

To execute a block of code a specific number of times

c)

To execute a block of code while a condition is true

d)

To define a function

6.

Which of the following is a correct way to define a dictionary in Python?

a)

`my_dict = {"name": "Alice", "age": 25}`

b)

`my_dict = ["name", "Alice", "age", 25]`

c)

`my_dict = ("name", "Alice", "age", 25)`

d)

`my_dict = {"name", "Alice", "age", 25}`

7.

What is the result of the following expression: 5+3×25 + 3 \times 2 ?

a)

16

b)

13

c)

11

d)

10

8.

Which of the following is a correct way to concatenate two strings in Python?

a)

`"Hello" + "World"`

b)

`"Hello" - "World"`

c)

`"Hello" * "World"`

d)

`"Hello" / "World"`

9.

What is the output of the following code? ```python for i in range(3): print(i) ```

a)

1 2 3

b)

0 1 2

c)

0 1 2 3

d)

1 2 3 4

10.

Which of the following is a correct way to check if a key exists in a dictionary?

a)

`if "key" in my_dict:`

b)

`if my_dict.has_key("key"):`

c)

`if my_dict.contains("key"):`

d)

`if "key" exists in my_dict:`

11.

What is the output of the following code snippet? ```python print(len("Python")) ```

a)

5

b)

6

c)

7

d)

8

12.

Which of the following is a valid way to create a list in Python?

a)

`my_list = (1, 2, 3)`

b)

`my_list = [1, 2, 3]`

c)

`my_list = {1, 2, 3}`

d)

`my_list = <1, 2, 3>`

13.

What is the output of the following code? ```python print(2 ** 3) ```

a)

6

b)

8

c)

9

d)

12

14.

Which of the following is a correct way to import the `math` module in Python?

a)

`import math`

b)

`include math`

c)

`using math`

d)

`require math`

15.

What is the output of the following code snippet? ```python print("Python".lower()) ```

a)

PYTHON

b)

python

c)

Python

d)

pYTHON

16.

Which of the following is a correct way to define a function in Python?

a)

`def my_function():`

b)

`function my_function()`

c)

`func my_function()`

d)

`define my_function()`

17.

What is the output of the following code? ```python print(type(3.14)) ```

a)

``

b)

``

c)

``

d)

``

18.

Which of the following is a correct way to create a tuple in Python?

a)

`my_tuple = [1, 2, 3]`

b)

`my_tuple = (1, 2, 3)`

c)

`my_tuple = {1, 2, 3}`

d)

`my_tuple = <1, 2, 3>`

19.

What is the output of the following code snippet? ```python print("Python".replace("P", "J")) ```

a)

Jython

b)

Jython

c)

Python

d)

Jython

20.

Which of the following is a correct way to open a file in read mode in Python?

a)

`open("file.txt", "r")`

b)

`open("file.txt", "w")`

c)

`open("file.txt", "a")`

d)

`open("file.txt", "x")`