Foundations
Complete Final Assessment (Qns & Ans)
2025
Question 1 (Multiple Choice)
Case:
A developer is writing a Python script to automate data
processing. The script reads from an input file, but there is a risk
that the file might be missing. The developer needs to handle this
error gracefully without terminating the program.
Question:
Which error handling construct in Python is most appropriate to
address the missing file scenario?
A. Wrap the file reading code in a `try/except` block catching a
generic `Exception`
©2025
,B. Use a bare `except` clause to catch all exceptions
C. Use a `try/except` block specifically catching
`FileNotFoundError`
D. Rely on the operating system’s error messaging to inform the
user
Correct ANS: C. Use a `try/except` block specifically
catching `FileNotFoundError`
Rationale:
Catching the specific exception (`FileNotFoundError`) ensures
that only the error related to the missing file is handled, allowing
the script to manage it gracefully while leaving other exceptions
unmasked for proper debugging.
---
Question 2 (Fill in the Blank)
Case:
In many scripting languages such as Python, variables declared
outside of any function are accessible throughout the program
unless shadowed by a local declaration.
©2025
, Statement:
Variables defined outside functions have ______ scope.
Correct ANS: global
Rationale:
Global variables are those that are declared at the top level of a
script (or module) and are accessible within functions unless a
local variable of the same name is defined.
---
Question 3 (True/False)
Case:
Languages like Python and JavaScript do not require explicit data
type declarations because they use dynamic typing.
Statement:
Dynamic typing in scripting languages means that the type of a
variable is determined at runtime.
Correct ANS: True
©2025
, Rationale:
Dynamic typing means that variable types are assigned during
execution, which offers flexibility in coding but can also lead to
runtime type-related errors if not managed properly.
---
Question 4 (Multiple Response)
Case:
A programmer is debugging a recursive function that processes
hierarchical data. To optimize this recursive logic and prevent
unnecessary calls, several techniques could be considered.
Question:
Which of the following methods can be used to optimize recursive
functions? (Select all that apply.)
A. Tail recursion optimization
B. Memoization
C. Converting recursion to iteration
D. Simply increasing the recursion limit without modifying the
algorithm
©2025