Questions and Detailed Solutions Latest Update 2026/2027 |
Southern New Hampshire University | Downloadable PDF - 180
Questions
This comprehensive final exam covers the core concepts of introductory scripting including variables and data
types, control structures, functions, strings, lists, dictionaries, file handling, exception handling, and basic
algorithmic thinking. The exam emphasizes problem-solving and debugging in Python. It contains 180
multiple-choice questions, each with four distractors and a fully worked rationale that explains why the keyed
answer is correct. Questions are organized into clearly labelled sections that mirror the major content areas of
the course. Targeted learning outcomes include: Analyze and design algorithmic solutions to computational
problems; Implement programs using Python with proper syntax and structure; Debug and test code using best
practices; Apply data structures such as lists, dictionaries, and strings to solve problems. Every item has been
reviewed for clinical accuracy, current guidelines, and clarity so that students can study with confidence and
self-correct as they work through the bank. Use it as a high-yield review immediately before the exam, or as a
structured practice tool during the unit - the rationales double as concise teaching notes. The recommended
writing time is 3 hours, with a passing score of 70%. Aligned with This exam adheres to the academic standards
of Southern New Hampshire University and aligns with typical introductory scripting curricula at accredited US
universities. standards and reflects the question style commonly seen on accredited program examinations.
Students consistently achieving above the cut score on this bank have historically gone on to earn A+ on the
Section 1: General (Questions 1-180)
1 Consider the following Python code snippet. What is the final value
of the variable `result`?
```python
def mystery(x, y):
while x != y:
if x > y:
x=x-y
else:
y=y-x
return x
result = mystery(48, 18)
```
A) 6
B) 18
,C) 30
D) 48
Answer: A
Rationale: The function computes the greatest common divisor (GCD)
of 48 and 18 using the Euclidean algorithm. The GCD is 6. Options B,
C, and D are intermediate values or inputs, not the final result.
2 Which of the following expressions evaluates to `True` in Python?
A) [] == None
B) 0 == False
C) '' == ' '
D) 1 == True and 2 == True
Answer: B
Rationale: In Python, 0 is considered equal to False and 1 is equal to
True. An empty list is not equal to None, an empty string is not equal
to a space, and 2 is not equal to True. Thus, only B is correct.
3 What will be the output of the following code?
```python
s = 'hello world'
print(s[::-1])
```
A) dlrow olleh
B) hello world
C) world hello
D) olleh
Answer: A
Rationale: The slice `[::-1]` reverses the entire string. The reversed
string is 'dlrow olleh'. The other options are incorrect because they do
not represent the full reversal.
,4 Which of the following statements about Python dictionaries is
TRUE?
A) Dictionary keys must be strings.
B) Dictionaries are ordered by default in Python 3.6 and earlier.
C) Dictionary values must be immutable.
D) Dictionary keys must be immutable.
Answer: D
Rationale: In Python, dictionary keys must be of an immutable type,
such as strings, numbers, or tuples. Values can be any type.
Dictionaries maintain insertion order only from Python 3.7 onwards,
not 3.6.
5 Consider the following code:
```python
try:
x = int('abc')
except ValueError:
print('ValueError')
except TypeError:
print('TypeError')
else:
print('No error')
finally:
print('Finally')
```
What is the output?
A) ValueError
Finally
B) TypeError
Finally
, C) No error
Finally
D) ValueError
No error
Finally
Answer: A
Rationale: `int('abc')` raises a ValueError, which is caught by the first
except block. The else block is skipped because an exception
occurred, but the finally block always executes. Thus, the output is
'ValueError' followed by 'Finally'.
6 What is the time complexity of the following function? (Assume n
is the length of list L)
```python
def contains_duplicate(L):
for i in range(len(L)):
for j in range(i+1, len(L)):
if L[i] == L[j]:
return True
return False
```
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(1)
Answer: C
Rationale: The nested loops compare each element with every
subsequent element, leading to about n(n-1)/2 comparisons, which is
O(n^2). The other options underestimate the growth rate.
7 Which of the following Python expressions will NOT raise an
exception?