ACTUAL OBJECTIVE ASSESSMENT PRACTICE
2026/2027 | Verified Code-Centric &
Scenario-Based Questions and Answers |
Grade A Target | Pass Guaranteed
Section 1: Python Foundations & Scripting Environment (Questions 1-10)
Q1: An IT automation script needs to process server hostnames that follow the pattern web-
01.prod.company.com. Which Python data structure is most appropriate for storing these
hostnames when the primary operations will be checking for membership (is this server in the
pool?) and ensuring no duplicates exist?
A. hostnames = ["web-01.prod.company.com", "web-02.prod.company.com"]
B. hostnames = ("web-01.prod.company.com", "web-02.prod.company.com")
C. hostnames = {"web-01.prod.company.com", "web-02.prod.company.com"} [CORRECT]
D. hostnames = "web-01.prod.company.com,web-02.prod.company.com"
Correct Answer: C
Rationale: A set (C) is the optimal choice for membership testing and deduplication. Sets
provide O(1) average-case lookup time for membership tests (in operator) versus O(n) for lists
and tuples. Sets inherently prevent duplicates, which is critical for server pools.
• Option A (list) allows duplicates and has slower membership testing.
• Option B (tuple) is immutable and also has O(n) membership testing.
• Option D (string) would require parsing and cannot represent multiple distinct
hostnames as separate elements without additional processing.
Pythonic best practice: Use sets when uniqueness and membership testing are primary
concerns, as in load balancer pools, firewall rule sets, or inventory management.
Q2: A system administrator writes the following script to check disk usage. What will be the
output?
,Python
Copy
#!/usr/bin/env python3
import sys
def check_disk(usage):
if usage > 90:
return "CRITICAL"
elif usage > 75:
return "WARNING"
return "OK"
try:
disk_usage = int(sys.argv[1])
status = check_disk(disk_usage)
print(f"Disk status: {status}")
except (IndexError, ValueError):
print("Usage: script.py <disk_usage_percent>")
sys.exit(1)
When executed as python3 script.py 85, what is printed?
A. Disk status: CRITICAL
B. Disk status: WARNING [CORRECT]
C. Disk status: OK
D. Usage: script.py <disk_usage_percent>
Correct Answer: B
Rationale: The value 85 is passed as a command-line argument, converted to integer 85. In
check_disk():
, • 85 > 90 is False, so not CRITICAL
• 85 > 75 is True, so returns "WARNING"
The elif condition is satisfied first, and the function returns immediately. The try/except block
handles the case where no argument is provided (IndexError) or a non-integer is provided
(ValueError).
• Option A would require > 90.
• Option C would require ≤ 75.
• Option D would trigger if no argument or non-integer was provided.
Best practice: Using sys.exit(1) indicates error status to calling processes/shell scripts, enabling
proper automation workflow handling.
Q3: [Multiple Response] Which of the following are valid ways to create a virtual environment
for Python 3.9+ and activate it on a Linux system? (Select all that apply.)
A. python3 -m venv /opt/automation/venv then source /opt/automation/venv/bin/activate
[CORRECT]
B. virtualenv /opt/automation/venv then source /opt/automation/venv/bin/activate [CORRECT]
C. python3 -m virtualenv /opt/automation/venv then . /opt/automation/venv/bin/activate
[CORRECT]
D. venv /opt/automation/venv then source /opt/automation/venv/Scripts/activate
Correct Answers: A, B, C
Rationale:
• A: The standard library venv module is the modern, recommended approach (PEP 405).
Activation uses source (or .) on the activate script in bin/ (Linux/macOS).
• B: The third-party virtualenv package remains valid and widely used, especially for older
Python versions or advanced features.
• C: Running virtualenv as a module via -m is valid syntax and equivalent to standalone
virtualenv command.
D is incorrect because:
• venv is not a standalone command; it must be called as python3 -m venv
• Scripts/activate is the Windows path; Linux uses bin/activate
, Operational note: Virtual environments isolate dependencies, preventing conflicts between
system Python packages and automation script requirements. Always document
requirements.txt and venv creation in deployment playbooks.
Q4: A log processing script uses the following pattern. What potential issue exists?
Python
Copy
def process_logs(log_files):
results = []
for file in log_files:
f = open(file, 'r')
data = f.read()
results.append(parse_log(data))
f.close()
return results
A. The script will fail if log_files contains non-existent files
B. File handles may not be closed if parse_log() raises an exception [CORRECT]
C. The results list will contain duplicate entries
D. Reading entire files into memory is inefficient for large logs
Correct Answer: B
Rationale: While D is technically true (streaming/lazy reading is better for large files), B
represents a critical resource leak bug. If parse_log(data) raises an exception, f.close() never
executes, leaving file descriptors open. On long-running automation jobs processing thousands
of logs, this causes "too many open files" errors (OSError: [Errno 24]).
The Pythonic solution uses context managers:
Python
Copy
with open(file, 'r') as f: