Module 3 Graded Quiz: Python Programming Fundamentals:Python for Data Science, AI & Development (IBM Data Analyst Professional Certificate) Answers 2025
1. Question 1
What is the output of the code?
-
❌ Go Stop
-
✅ Stop Mike
-
❌ Go Mike
-
❌ Mike
Explanation:x == "Go" is false, so print('Stop') runs, then print('Mike') — output is Stop then Mike.
2. Question 2
Primary purpose of comparison operators in assignment statements?
-
❌ To convert numeric variables to string representations
-
✅ To evaluate expressions and assign the resulting Boolean values to variables
-
❌ To initialize variables with their default values
-
❌ To perform mathematical operations on both sides of the equation
Explanation:
Comparison operators (==, <, >, etc.) return True/False, which are often assigned to variables for decision logic.
3. Question 3
What determines when a while loop terminates?
-
✅ The evaluation of its conditional expression to False
-
❌ The presence of a print statement within the loop
-
❌ The number of statements inside the loop body
-
❌ While loops always execute exactly five times by default
Explanation:
A while loop runs while its condition is True and stops once that condition becomes False.
4. Question 4
Result of the class example when calling p1.print_point()?
-
❌ y=B
-
❌ x=A
-
❌ x=y=
-
✅ x=A y=B
Explanation:print('x=', self.x, ' y=', self.y) outputs x= A y= B (commonly represented as x=A y=B).
5. Question 5
Output of the for i, x in enumerate(['A','B','C']): print(i, 2*x) loop?
-
✅ 0 AA 1 BB 2 CC
-
❌ 0 A 1 B 2 C
-
❌ 0 A 2 B 4 C
-
❌ 1 AA 2 BB 3 CC
Explanation:enumerate yields (index, value). 2 * x duplicates the string: 'A'->'AA', so lines are 0 AA, 1 BB, 2 CC.
6. Question 6
Result after modifying p2.y = 'Denver' and printing?
-
❌ x= Denver y= Boston
-
❌ x= Boston y= Chicago
-
✅ x= Boston y= Denver
-
❌ x= Denver y= Denver
Explanation:x remains 'Boston'; y was reassigned to 'Denver', so print shows x= Boston y= Denver.
7. Question 7
What does validate_temperature(32) return?
-
❌ “Invalid”
-
✅ “Valid”
-
❌ False
-
❌ None
Explanation:
32 lies between 20 and 40, so the function sets result = "Valid" and returns it.
8. Question 8
What does print(do(1)) produce given the local a = 100 inside do?
-
❌ Product of local variable and parameter
-
❌ Sum of global variable and parameter
-
✅ Sum of local variable and parameter
-
❌ Value of global variable only
Explanation:
Inside do, a is a local variable (100). do(1) returns 1 + 100 = 101 — sum of local a and parameter.
9. Question 9
Most efficient implementation for adding two numbers?
-
❌ Built-in sum with tuple conversion
-
❌ Built-in sum with individual parameters
-
✅ Direct return of parameter summation
-
❌ Intermediate variable assignment before return
Explanation:
The simplest and most efficient is def add(a, b): return a + b — direct return avoids overhead.
10. Question 10
Why use multiple except blocks labeled by error type?
-
❌ Ensure catching the error for program termination
-
✅ To determine the type of error thrown and its location within the program
-
❌ To skip specific sections of code during execution
-
❌ It is not necessary to label errors
Explanation:
Multiple, specific except blocks let you handle different exception types appropriately and make debugging (and correct recovery) easier.
🧾 Summary Table
| Q# | Correct Answer | Key Idea |
|---|---|---|
| 1 | Stop Mike | if condition false → else runs, then subsequent print |
| 2 | Assign Boolean results | Comparisons yield True/False |
| 3 | Condition becomes False | while stops when condition is False |
| 4 | x=A y=B | Method prints both attributes |
| 5 | 0 AA 1 BB 2 CC | enumerate + string repetition |
| 6 | x= Boston y= Denver | Attribute reassignment persists |
| 7 | “Valid” | 32 within the valid range |
| 8 | Sum of local var & param | Local a=100 used in sum |
| 9 | Direct return a + b |
Simpler and fastest |
| 10 | Identify error types & locations | Specific except blocks aid handling & debugging |