Final Exam | Complete Exam with Actual Questions and
Correct Verified Answers (Rationales Included) | Latest
Update 2026/2027 - Already Graded A+
Question 1
What is the output of the following code? print(3 + 2 * 4)
A. 24
B. 11
C. 20
D. 14
Answer: B
Rationale: Operator precedence: multiplication before addition. 2 * 4 = 8, then 3 + 8 =
11.
Question 2
What is the correct way to output the string "Hello, World!" in Python?
A. echo "Hello, World!"
B. printf("Hello, World!")
C. print("Hello, World!")
D. console.log("Hello, World!")
Answer: C
Rationale: In Python, the built-in print() function outputs text to the console. The
other options are used in other languages.
Question 3
What is the output of the following code? print(5 == 5)
A. True
B. 10
C. False
D. 5
pg. 1
,Answer: A
Rationale: The == operator checks for equality. 5 == 5 is True.
Question 4
What is the output of the following code? print(type(3.14))
A. <class 'str'>
B. <class 'float'>
C. <class 'int'>
D. <class 'double'>
Answer: B
Rationale: In Python, numbers with decimal points are float type. 3.14 is a floating-
point number.
Question 5
What is the output of the following code? x = 5; x += 3; print(x)
A. 15
B. 3
C. 5
D. 8
Answer: D
Rationale: The += operator adds the right operand to the left operand and assigns the
result. x += 3 is equivalent to x = x + 3, so 5 + 3 = 8.
Question 6
What is the output of the following code? for i in range(3): print(i, end=" ")
A. 0 1 2 3
B. 1 2 3
C. 0 1 2
D. 1 2 3 4
Answer: C
Rationale: range(3) generates numbers from 0 to 2 (exclusive of 3). The loop prints 0,
1, 2.
pg. 2
,Question 7
What is the output of the following code? print("Hello"[::-1])
A. olleH
B. elloH
C. Hello
D. H
Answer: A
Rationale: The slice [::-1] reverses a string by stepping backwards through it.
Question 8
What is the result of int("3.14")?
A. 4
B. 3.14
C. 3
D. Error
Answer: D
Rationale: int() cannot convert a string representing a float with a decimal point
directly. It will raise a ValueError.
Question 9
Which type of loop is best used when the number of iterations is unknown?
A. for loop
B. while loop
C. nested loop
D. for-each loop
Answer: B
Rationale: A while loop runs until a condition becomes False, making it ideal when the
number of iterations is not known in advance.
Question 10
What is the output of the following code? my_list = [1, 2, 3]; my_list.append(4);
print(my_list)
A. [4, 1, 2, 3]
B. [1, 2, 3]
pg. 3
, C. [1, 2, 3, 4]
D. Error
Answer: C
Rationale: The append() method adds an element to the end of a list.
Question 11
What is the output of the following code? def add(a, b): return a + b; print(add(3, 4))
A. None
B. Error
C. 34
D. 7
Answer: D
Rationale: The function add takes two arguments and returns their sum. 3 + 4 = 7.
Question 12
What is the output of the following code? print(10 // 3)
A. 3.0
B. 4
C. 3.33
D. 3
Answer: D
Rationale: Floor division (//) returns the integer quotient. 10 // 3 = 3.
Question 13
Which of the following is a mutable data structure?
A. list
B. int
C. string
D. tuple
Answer: A
Rationale: Lists are mutable and can be modified after creation. Tuples, strings, and
integers are immutable.
pg. 4