Download WGU D335: Introduction to Programming in Python Objective Assessment (OA) Practice Test B and more Exams Nursing in PDF only on Docsity!
WGU D335: Introduction to Programming in Python Objective Assessment (OA) Practice Test Bank 2026 500 Exam-Style Questions with Verified Answers & Detailed Rationales EXAM OVERVIEW WGU D335: Introduction to Programming in Python is a competency-based course within Western Governors University's College of Information Technology. The course introduces skills in creating Python scripts with basic programming concepts, including control flow with functions and loops, and implementing code with packages, modules, and libraries. Course Competencies The learner will develop competency in the following areas:
- Implementing code with basic programming concepts – Variables, data types, operators, expressions, and input/output operations
- Creating control flow with functions and loops – Conditional statements, loops, function definition and invocation, and parameter passing
- Implementing code with packages, modules, and libraries – Importing and using standard library modules, working with files, and handling exceptions Objective Assessment (OA) Format Feature Detail
Assessment Type Performance-based, code-writing exam
Format Approximately 15 coding questions Passing Score 80% (12 correct selections out of 15) Environment zyBooks auto-grader Critical Requirement Exact whitespace, capitalization, and output format matching Domain Weightings Domain Percentage
Python Fundamentals & Syntax 25% Data Types & Structures 25% Control Flow & Loops 20% Functions & Modules 15% File I/O & Exception Handling 10% Problem Solving & Algorithms 5% Key Focus Areas for the OA Based on student feedback and exam analysis, the following areas are heavily tested:
- String Formatting – f-strings, .format(), format specifiers (precision, alignment, padding)
- File I/O – Reading and writing files, context managers, csv module, sys.argv
- Dictionary Manipulation – Weighted sums, lookups, iteration, comprehensions
- Error Handling – try/except, sys.argv validation
- Unit Conversions – Floor division (//) and modulus (%) for converting between units
- Data Structures – Lists, dictionaries, zip(), slicing
SECTION 1: PYTHON FUNDAMENTALS & SYNTAX (Questions 1–125) IPO model, variables, algorithms, assignment operators, print(), input(), comments, indentation, syntax errors, runtime errors, logical errors
- A program consists of which three basic instruction types? A. Read, Write, Execute B. Input, Process, Output C. Compile, Link, Run D. Define, Call, Return Answer: B Rationale: Every program follows the IPO model: it takes input (from keyboard, file, etc.), processes that data (computations, logic), and produces output (to screen, file, etc.).
- What is a variable in Python? A. A fixed value that cannot change B. A named reference to a value stored in memory
C. A type of loop structure D. A function that prints output Answer: B Rationale: A variable is a named item used to hold a value. It acts as a reference or label that points to an object in memory. Variables can be reassigned to different values.
- What is an algorithm? A. A type of Python data structure B. A sequence of instructions that solves a problem C. A built-in Python function D. An error in program execution Answer: B Rationale: An algorithm is a step-by-step sequence of instructions designed to solve a specific problem or accomplish a task.
- What does the assignment operator = do in Python? A. Compares two values for equality
A. .java B. .py C. .cpp D. .txt Answer: B Rationale: Python scripts are saved with the .py file extension.
- What does the print() function do in Python? A. Reads input from the user B. Outputs data to the screen C. Writes data to a file D. Creates a new variable Answer: B Rationale: The print() function outputs data to the console or screen. It can accept multiple arguments and automatically adds a newline character at the end by default.
- What does the input() function do in Python?
A. Outputs data to the screen B. Reads input from the user and returns it as a string C. Writes data to a file D. Creates a new variable Answer: B Rationale: The input() function reads input from the user and returns it as a string. To use the input as a number, it must be converted using int() or float().
- What is the output of the following code?
x = 5 y = 3 print(x + y)
A. 53 B. 8 C. 5 + 3 D. Error Answer: B
Answer: B Rationale: The type() function returns the data type of the object passed to it. For example, type(5) returns ``.
- What is the difference between = and == in Python? A. They are the same B. = assigns, == compares C. = compares, == assigns D. Both assign values Answer: B Rationale: = is the assignment operator that assigns a value to a variable. == is the equality operator that compares two values and returns True or False.
- What is a syntax error? A. An error that occurs during program execution B. A violation of the programming language's rules on how symbols can be defined C. An error in the program's logic D. An error in the output
Answer: B Rationale: A syntax error is a violation of the programming language's rules on how symbols can be defined. Syntax errors are detected before the program runs.
- What is a runtime error? A. An error detected before the program runs B. An error that occurs when the program attempts an impossible operation C. An error in the program's logic D. An error in the output Answer: B Rationale: A runtime error occurs when the program attempts an impossible operation, such as dividing by zero or accessing a non-existent index.
- What is a logical error? A. An error detected before the program runs B. An error that occurs during program execution C. An error in the program's logic that produces incorrect results
A. To make the code look pretty B. To define blocks of code C. To indicate comments D. To separate variables Answer: B Rationale: Python uses indentation to define blocks of code. Consistent indentation is required for loops, conditionals, functions, and other block structures.
- What is the output of the following code?
print(10 / 3)
A. 3 B. 3. C. 3. D. Error Answer: C Rationale: The / operator performs true division and returns a float. 10 / 3 evaluates to 3.3333333333333335.
- What is the output of the following code?
print(10 // 3)
A. 3. B. 3 C. 4 D. Error Answer: B Rationale: The // operator performs floor division and returns the integer part of the quotient. 10 // 3 evaluates to 3.
- What is the output of the following code?
print(10 % 3)
A. 3
- Which of the following is a valid string in Python? A. 'Hello' B. "Hello" C. '''Hello''' D. All of the above Answer: D Rationale: Python supports single quotes, double quotes, and triple quotes for strings. Triple quotes are used for multi-line strings.
- What is the output of the following code?
x = "5" y = "3" print(x + y)
A. 8 B. 53 C. Error D. 5 + 3
Answer: B Rationale: When + is used with strings, it performs concatenation. The strings "5" and "3" are concatenated to produce "53".
- How do you convert a string to an integer in Python? A. str(value) B. int(value) C. float(value) D. bool(value) Answer: B Rationale: The int() function converts a string or float to an integer. For example, int("5") returns 5.
- How do you convert an integer to a string in Python? A. int(value) B. str(value) C. float(value)
print(bool(""))
A. True B. False C. Error D. Empty string Answer: B Rationale: An empty string "" evaluates to False when converted to a boolean.
- What is the purpose of the float() function? A. Converts a value to an integer B. Converts a value to a string C. Converts a value to a floating-point number D. Converts a value to a boolean Answer: C Rationale: The float() function converts a value to a floating-point number. For example, float("3.14") returns 3.14.
- What is the output of the following code?
x = 5 x = x + 1 print(x)
A. 5 B. 6 C. 1 D. Error Answer: B Rationale: The variable x is initially assigned the value 5. The line x = x + 1 reassigns x to 6. The output is 6.
- What is the output of the following code?
x = 5 x += 1