wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSB 2nd 9-Weeks Final Exam

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is Python?

a)

A programming language

b)

A web browser

c)

A text editor

d)

An operating system

2.

Which of the following is a correct way to comment a single line in Python?

a)

// This is a comment

b)

/* This is a comment */

c)

# This is a comment

d)

; This is a comment

3.

What is the correct way to print "Hello, World!" to the console in Python?

a)

print("Hello, World!")

b)

Console.WriteLine("Hello, World!")

c)

echo "Hello, World!"

d)

System.out.println("Hello, World!")

4.

What is a variable in Python?

a)

A reserved keyword

b)

A data type

c)

A memory location to store a value

d)

A function

5.

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

a)

123variable

b)

my_variable

c)

my-variable

d)

my variable

6.

What is the data type of the value 3.14?

a)

int

b)

float

c)

str

d)

bool

7.

What is the result of the following expression: 5 + 3 * 2?

a)

16

b)

11

c)

13

d)

10

8.

What is the purpose of the if statement?

a)

To define a function

b)

To create a loop

c)

To execute a block of code conditionally

d)

To declare a variable

9.

What is the correct way to define a function in Python?

a)

function my_function():

b)

def my_function():

c)

function my_function:

d)

define my_function():

10.

What is the purpose of the for loop?

a)

To execute a block of code repeatedly

b)

To define a function

c)

To make decisions

d)

To create a list

11.

Which of the following is NOT a basic data type in Python?

a)

int

b)

float

c)

string

d)

array

12.

What is the difference between == and = operators?

a)

== is used for assignment, = is used for comparison.

b)

= is used for assignment, == is used for comparison.

c)

Both are used for assignment.

d)

Both are used for comparison.

13.

What is the purpose of the len() function?

a)

To calculate the square root of a number.

b)

To find the length of a string or list.

c)

To convert a number to a string.

d)

To sort a list.

14.

How do you create a list in Python?

a)

list = [1, 2, 3]

b)

list(1, 2, 3)

c)

[1, 2, 3]

d)

list = {1, 2, 3}

15.

What is the correct way to access the last element of a list named my_list?

a)

my_list[-1]

b)

my_list[len(my_list)]

c)

my_list[-2]

d)

my_list[len(my_list) - 1]

16.

What is the correct way to define a variable and assign it the value 10 in Python?

a)

var x = 10

b)

int x = 10

c)

x = 10

d)

let x = 10

17.

How do you check if a number is even or odd in Python?

a)

Using the even() function

b)

Using the modulo operator (%)

c)

Using the is_even() function

d)

Using the odd() function

18.

What is the purpose of the break statement in a loop?

a)

To continue to the next iteration of the loop

b)

To exit the loop immediately

c)

To pause the loop

d)

To restart the loop

19.

Which of the following is NOT a common string method in Python?

a)

upper()

b)

lower()

c)

capitalize()

d)

sort()

20.

What is the output of the following code: Python x = 10 y = 5 print(x % y)

a)

2

b)

0

c)

5

d)

1

21.

How do you access the third element of a list named my_list?

a)

my_list[2]

b)

my_list[3]

c)

my_list(2)

d)

my_list(3)

22.

What is the output of the following code: Python x = "Hello, World!" print(x[7])

a)

'W'

b)

'o'

c)

'l'

d)

'd'

23.

What is the output of the following code: Python x = [1, 2, 3, 4, 5] x.append(6) print(x)

a)

[1, 2, 3, 4, 5]

b)

[6, 1, 2, 3, 4, 5]

c)

[1, 2, 3, 4, 5, 6]

d)

[1, 2, 3, 4]

24.

What is the output of the following code: print(x.upper())

a)

['Hello', ' World!']

b)

['Hello', 'World!']

c)

['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!']

d)

'HELLO, WORLD!'

25.

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

a)

"x is greater than y"

b)

"y is greater than or equal to x"

c)

"x is equal to y"

d)

None of the above