OBJECTIVE ASSESSMENT: EXAM
(LATEST 2026/2027 UPDATE), |
QUESTIONS & ANSWERS| GRADE A|
100% CORRECT (VERIFIED SOLUTIONS)
WGU D335 INTRO TO PYTHON | OA |
OBJECTIVE ASSESSMENT
WGU D335 – Introduction to Python
(OA Objectives)
1.
A program accepts an integer representing a pig’s age and converts it to human years
using a provided module function. If a pig year equals five human years, what is the
correct output for input 4?
A. 9
B. 20
C. 25
D. 4
Correct Answer: B
Rationale:
The problem states that one pig year equals five human years. When the input value
is 4, the conversion is 4 × 5 = 20. The function simply multiplies the input integer by
five, with no additional logic or formatting required. This tests basic arithmetic and
function usage with imported modules.
,2.
Which statement correctly imports a module named pigAge?
A. import pigage
B. include pigAge
C. from pigAge import *
D. import pigAge
Correct Answer: D
Rationale:
Python module names are case-sensitive, so pigAge must be imported exactly as
named. The import pigAge statement imports the module correctly and allows access
via dot notation. While option C can work in some cases, it is discouraged and not
required. Option D is the cleanest and expected answer.
3.
What does the following code do?
pig_age = int(input()) print(pig_age * 5)
A. Converts pig years to dog years
B. Converts pig years to human years
C. Prints input unchanged
D. Raises a TypeError
Correct Answer: B
Rationale:
The code multiplies the input value by five, which represents the conversion from pig
years to human years. The int(input()) ensures numeric input for arithmetic
operations. There are no syntax or runtime errors in the code. This is a straightforward
conversion calculation.
,4.
What is the purpose of using int(input()) instead of just input()?
A. To prevent exceptions
B. To convert user input to an integer
C. To format output
D. To speed up execution
Correct Answer: B
Rationale:
The input() function returns a string by default. Converting it with int() allows the
value to be used in mathematical operations. Without conversion, attempting
arithmetic would raise a TypeError. This is a fundamental concept in Python input
handling.
5.
What happens if the user inputs a non-numeric value when int(input()) is used?
A. Program exits normally
B. Value is treated as zero
C. A ValueError occurs
D. The input is ignored
Correct Answer: C
Rationale:
When int() receives a string that cannot be converted to an integer, Python raises
a ValueError. This is why exception handling is often used when accepting user input.
The program does not automatically recover unless a try/except block is implemented.
This behavior is consistent across Python versions.
, 6.
Which keyword is used to handle exceptions in Python?
A. catch
B. handle
C. except
D. error
Correct Answer: C
Rationale:
Python uses try and except blocks for exception handling. The except keyword
specifies how the program should respond when an error occurs. This mechanism
prevents program crashes and allows graceful error messages. It replaces
the catch keyword found in other languages.
7.
What is the output if the index is out of range in the following code?
try: print(frameworks[index]) except: print("Error")
A. Program crashes
B. Nothing prints
C. IndexError
D. Error
Correct Answer: D
Rationale:
The except block catches any exception that occurs in the try block. If the index is out
of range, an IndexError is raised. Instead of crashing, the program prints "Error". This
demonstrates defensive programming.