WorksheetsCSB 2nd 9-Weeks Final Exam
Total questions: 25
Worksheet time: 13mins
What is Python?
A programming language
A web browser
A text editor
An operating system
Which of the following is a correct way to comment a single line in Python?
// This is a comment
/* This is a comment */
# This is a comment
; This is a comment
What is the correct way to print "Hello, World!" to the console in Python?
print("Hello, World!")
Console.WriteLine("Hello, World!")
echo "Hello, World!"
System.out.println("Hello, World!")
What is a variable in Python?
A reserved keyword
A data type
A memory location to store a value
A function
Which of the following is a valid variable name in Python?
123variable
my_variable
my-variable
my variable
What is the data type of the value 3.14?
int
float
str
bool
What is the result of the following expression: 5 + 3 * 2?
16
11
13
10
What is the purpose of the if statement?
To define a function
To create a loop
To execute a block of code conditionally
To declare a variable
What is the correct way to define a function in Python?
function my_function():
def my_function():
function my_function:
define my_function():
What is the purpose of the for loop?
To execute a block of code repeatedly
To define a function
To make decisions
To create a list
Which of the following is NOT a basic data type in Python?
int
float
string
array
What is the difference between == and = operators?
== is used for assignment, = is used for comparison.
= is used for assignment, == is used for comparison.
Both are used for assignment.
Both are used for comparison.
What is the purpose of the len() function?
To calculate the square root of a number.
To find the length of a string or list.
To convert a number to a string.
To sort a list.
How do you create a list in Python?
list = [1, 2, 3]
list(1, 2, 3)
[1, 2, 3]
list = {1, 2, 3}
What is the correct way to access the last element of a list named my_list?
my_list[-1]
my_list[len(my_list)]
my_list[-2]
my_list[len(my_list) - 1]
What is the correct way to define a variable and assign it the value 10 in Python?
var x = 10
int x = 10
x = 10
let x = 10
How do you check if a number is even or odd in Python?
Using the even() function
Using the modulo operator (%)
Using the is_even() function
Using the odd() function
What is the purpose of the break statement in a loop?
To continue to the next iteration of the loop
To exit the loop immediately
To pause the loop
To restart the loop
Which of the following is NOT a common string method in Python?
upper()
lower()
capitalize()
sort()
What is the output of the following code: Python x = 10 y = 5 print(x % y)
2
0
5
1
How do you access the third element of a list named my_list?
my_list[2]
my_list[3]
my_list(2)
my_list(3)
What is the output of the following code: Python x = "Hello, World!" print(x[7])
'W'
'o'
'l'
'd'
What is the output of the following code: Python x = [1, 2, 3, 4, 5] x.append(6) print(x)
[1, 2, 3, 4, 5]
[6, 1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4]
What is the output of the following code: print(x.upper())
['Hello', ' World!']
['Hello', 'World!']
['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!']
'HELLO, WORLD!'
What is the output of the following code: x = 10 y = 20 if x > y: print("x is greater than y") else: print("y is greater than or equal to x")
"x is greater than y"
"y is greater than or equal to x"
"x is equal to y"
None of the above
