, DS 110 Final Exam Version 1 and Version 2 |
Full Questions and Answers | 2026/27 Updated |
100% Correct | with complete solutions -
Boston University.
SECTION 1: PYTHON FUNDAMENTALS — DATA
TYPES & VARIABLES (Questions 1–10)
1. What are the values of the variables a, b, and c after running this
code?
python
a = 3
b = 2
def my_func(a, b):
b += 2
a = a + b
return a
c = my_func(a, b)
A) a=3, b=2, c=7
B) a=5, b=4, c=7
C) a=7, b=4, c=7
D) a=3, b=4, c=7
Correct Answer: A
Rationale: In Python, integers are immutable, and function parameters are
passed by object reference. Inside my_func, a and b are local variables that
initially reference the same objects as the global a and b. However, when b
+= 2 executes, it creates a new local integer object for b (now 4). Then a =
a + b creates a new local integer (3 + 4 = 7). The global a and b remain
unchanged (3 and 2). The return value c is 7 .
Source: DS110 Final Flashcards — Quizlet