Actual Exam 2026/2027 –Verified Questions
with Rationales
Q1: You’re writing a script to calculate server uptime percentages for your
infrastructure team. You assign total_hours = 8760 and downtime = 43.5.
What is the data type of the result when you calculate uptime_percentage =
((total_hours - downtime) / total_hours) * 100?
A. Integer (int)
B. Floating-point number (float) [CORRECT]
C. String (str)
D. Boolean (bool)
Correct Answer: B
Rationale:✓✓ Even though total_hours is an integer, the division operation in
Python 3 always produces a float to maintain decimal precision. The subsequent
multiplication keeps it as a float, which is exactly what you need for precise
percentage calculations.
Q2: A junior developer asks why their boolean variable is_connected =
"False" evaluates to True in their conditional check. What is the root cause of
this unexpected behavior?
A. The variable name contains underscores which Python interprets as True
B. “False” as a string is truthy because it’s a non-empty string [CORRECT]
C. Boolean variables must be declared using the bool() constructor exclusively
D. Python treats all quoted text as logical True by default
Correct Answer: B
Rationale:✓✓ In Python, any non-empty string—including the text "False"—
evaluates to True in a boolean context. The quotes make it a string literal, not the
boolean False value. The correct assignment would be is_connected = False
without any quotes.
,Q3: You need to convert user input from a text file—stored as the string
"4500"—to an integer for memory allocation calculations. Which code
accomplishes this conversion correctly?
A. memory = "4500".toInteger()
B. memory = integer("4500")
C. memory = int("4500") [CORRECT]
D. memory = str(4500)
Correct Answer: C
Rationale:✓✓ Python’s built-in int() constructor converts strings to integers.
The toInteger() method doesn’t exist in Python, integer() isn’t a built-in function
name, and str() would convert an integer to a string, which is the opposite of what
you need.
Q4: While reviewing a configuration script, you encounter this
line: port_number = 8080 # Default port for the web service. How would you
categorize this comment according to Python conventions?
A. Block comment
B. Inline comment [CORRECT]
C. Docstring
D. Multi-line comment
Correct Answer: B
Rationale:✓✓ Text following a hash symbol (#) on the same line as executable
code constitutes an inline comment. Block comments typically appear on their own
lines before code, docstrings use triple quotes to describe functions or modules,
and Python doesn’t have formal multi-line comment syntax (it uses triple-quoted
strings instead).
Q5: A script contains the mathematical expression result = 15 // 4. What
integer value does the variable result hold after execution?
A. 3.75
B. 3 [CORRECT]
C. 4
D. 0
,Correct Answer: B
Rationale:✓✓ The // operator performs floor division (integer division). 15
divided by 4 is 3.75, and floor division truncates the decimal part, returning the
integer 3. The result is an int, not a float.
Q6: Which of the following is a valid way to check if a variable status is exactly
the integer 0?
A. if status is 0:
B. if status == 0: [CORRECT]
C. if status = 0:
D. if status equals 0:
Correct Answer: B
Rationale:✓✓ The equality operator == compares values. is checks object identity,
which may work for small integers due to interning but is not reliable. = is
assignment, not comparison. equals is not a Python keyword.
Q7: You need to iterate over a list of IP addresses and print each one. Which
loop correctly accomplishes this?
A. for i in range(ip_list): print(ip_list[i])
B. for ip in ip_list: print(ip) [CORRECT]
C. while ip in ip_list: print(ip)
D. foreach ip in ip_list: print(ip)
Correct Answer: B
Rationale:✓✓ Python’s for loop directly iterates over the elements of a list. Option
B is the simplest and most readable. Option A would require range(len(ip_list)).
Option C uses while incorrectly. Option D uses foreach, which is not Python
syntax.
Q8: What is the output of the following code? print(type())
A. <class ‘int’>
B. <class ‘float’> [CORRECT]
C. <class ‘complex’>
D. <class ‘str’>
, Correct Answer: B
*Rationale:✓✓ In Python 3, the / operator always returns a float, even if the
division yields an integer result (10/2 = 5.0).*
Q9: Which method is used to read an entire file into a single string?
A. file.read_all()
B. file.read() [CORRECT]
C. file.readline()
D. file.readlines()
Correct Answer: B
Rationale:✓✓ file.read() without arguments reads the entire content as one
string. readline() reads one line, readlines() returns a list of lines,
and read_all() does not exist.
Q10: You have a list of server names: servers = [“web01”, “db01”, “cache01”].
Which code replaces “db01” with “db02”?
A. servers[1] = “db02” [CORRECT]
B. servers[2] = “db02”
C. servers.replace(“db01”, “db02”)
D. servers[“db01”] = “db02”
Correct Answer: A
Rationale:✓✓ Lists are zero-indexed; “db01” is at index 1. Assignment to an
index changes the element. replace is a string method, not a list method. Using a
string as an index is invalid.
Q11: Which statement correctly creates an empty dictionary?
A. dict = []
B. dict = {} [CORRECT]
C. dict = ()
D. dict = set()