NEW
Font size
WorksheetsPython Basics Quiz for Grade 10
Total questions: 20
Worksheet time: 10mins
What is the output of the following Python code snippet? ```python print("Hello, World!"[7]) ```
H
W
o
,
Which of the following is a valid way to declare an integer variable in Python?
`int number = 5`
`number = 5`
`integer number = 5`
`num = "5"`
What will be the output of the following code? ```python import random print(random.randint(1, 10)) ```
A random integer between 1 and 10, inclusive
A random integer between 1 and 9, inclusive
A random float between 1 and 10
A random float between 0 and 1
Consider the following list: `fruits = ["apple", "banana", "cherry"]`. What is the result of `fruits[1]`?
apple
banana
cherry
None
What is the purpose of a for loop in Python?
To execute a block of code once
To execute a block of code a specific number of times
To execute a block of code while a condition is true
To define a function
Which of the following is a correct way to define a dictionary in Python?
`my_dict = {"name": "Alice", "age": 25}`
`my_dict = ["name", "Alice", "age", 25]`
`my_dict = ("name", "Alice", "age", 25)`
`my_dict = {"name", "Alice", "age", 25}`
What is the result of the following expression: 5+3×2 ?
16
13
11
10
Which of the following is a correct way to concatenate two strings in Python?
`"Hello" + "World"`
`"Hello" - "World"`
`"Hello" * "World"`
`"Hello" / "World"`
What is the output of the following code? ```python for i in range(3): print(i) ```
1 2 3
0 1 2
0 1 2 3
1 2 3 4
Which of the following is a correct way to check if a key exists in a dictionary?
`if "key" in my_dict:`
`if my_dict.has_key("key"):`
`if my_dict.contains("key"):`
`if "key" exists in my_dict:`
What is the output of the following code snippet? ```python print(len("Python")) ```
5
6
7
8
Which of the following is a valid way to create a list in Python?
`my_list = (1, 2, 3)`
`my_list = [1, 2, 3]`
`my_list = {1, 2, 3}`
`my_list = <1, 2, 3>`
What is the output of the following code? ```python print(2 ** 3) ```
6
8
9
12
Which of the following is a correct way to import the `math` module in Python?
`import math`
`include math`
`using math`
`require math`
What is the output of the following code snippet? ```python print("Python".lower()) ```
PYTHON
python
Python
pYTHON
Which of the following is a correct way to define a function in Python?
`def my_function():`
`function my_function()`
`func my_function()`
`define my_function()`
What is the output of the following code? ```python print(type(3.14)) ```
`
`
`
`
Which of the following is a correct way to create a tuple in Python?
`my_tuple = [1, 2, 3]`
`my_tuple = (1, 2, 3)`
`my_tuple = {1, 2, 3}`
`my_tuple = <1, 2, 3>`
What is the output of the following code snippet? ```python print("Python".replace("P", "J")) ```
Jython
Jython
Python
Jython
Which of the following is a correct way to open a file in read mode in Python?
`open("file.txt", "r")`
`open("file.txt", "w")`
`open("file.txt", "a")`
`open("file.txt", "x")`
