























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
WGU D278 Scripting and Programming Foundations Objective Assessment (OA) Practice Exam 100 Questions with Verified Answers and Detailed Rationales Western Governors University – Updated for 2026
Typology: Exams
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































The WGU D278 Scripting and Programming Foundations Objective Assessment covers fundamental programming concepts essential for success in the software development program. Key topics include:
Topic AreaWeight Core Programming Concepts (variables, operators, loops, conditionals)25-30% Functions and Modularization15-20% Data Structures (lists, dictionaries, tuples, sets)15-20% Object-Oriented Programming (OOP) Basics10-15% File Handling and Exception Management10-15% Debugging, Testing, and Best Practices5-10% JSON/CSV Handling and Automation5-10%Which mode opens a file for writing, erasing its contents if it already exists? A. 'r' B. 'w' C. 'a' D. 'r+' Answer: B. 'w' Rationale: 'w' mode opens a file for writing and overwrites the existing file (truncates it) or creates a new one if it doesn't exist.
QUESTION 2 What will happen if you try to open a non-existent file using open('missing.txt', 'r')? A. It creates a new file. B. It prints "File not found." C. It raises a FileNotFoundError. D. It returns an empty string. Answer: C. It raises a FileNotFoundError
D. Compiler error types Answer: C. Rules that define the structure of valid statements Rationale: Grammar in programming refers to the syntax rules that determine how valid statements and expressions can be formed in a language.
QUESTION 5 Which operator type produces a Boolean result? A. Arithmetic operator B. Assignment operator C. Boolean operator D. Relational operator Answer: D. Relational operator Rationale: Relational operators (>, <, >=, <=, ==, !=) compare values and produce Boolean results (true/false). Boolean operators also produce Boolean results, but relational operators are the ones used for comparisons.
QUESTION 6 What is the result of the following pseudocode when starting with x = 3?
WHILE (x < 3) // loop body
A. Loop runs twice B. Loop runs forever C. Loop never runs D. Loop runs once Answer: C. Loop never runs Rationale: The condition `x < 3` is checked before execution. Since `x = 3`, the condition is false, so the loop body never executes. --- QUESTION 7 A loop that never ends is called a: A. Skip loop B. Short loop C. Infinite loop D. False loop Answer: C. Infinite loop D. stop Answer: C. break Rationale: The `break` statement immediately terminates the loop and transfers execution to the statement following the loop. --- QUESTION 10 What does the `continue` statement do? A. Exits the program B. Skips to the next loop iteration C. Exits the loop D. Reverses loop direction Answer: B. Skips to the next loop iteration Rationale: The `continue` statement skips the rest of the current iteration and moves directly to the next iteration of the loop. --- QUESTION 11 What is the output of the following pseudocode?FOR i = 1 to 4 PRINT i
A. 2, 4 B. 1, 2, 3, 4 C. 4, 3, 2, 1 D. none Answer: B. 1, 2, 3, 4 Rationale: The for loop iterates with `i` taking values 1, 2, 3, and 4, printing each value in sequence. --- QUESTION 12 Which loop is ideal for input validation? A. For loop B. Do-while loop C. If-else statement D. Switch statement Answer: B. Do-while loop A. Assignment operator B. Equality operator C. Comparison operator D. Relational operator Answer: B. Equality operator Rationale: The `==` operator is the equality operator used to compare whether two values are equal. It is distinct from the assignment operator `=`. --- QUESTION 15 What term describes the result produced by a program after execution? A. Function B. Variable C. Output D. Input Answer: C. Output Rationale: Output is the data or results that a program produces after processing input. --- ## QUESTION 16 What does a Boolean value represent? A. Any numerical value B. One of three values: True, False, or Undefined C. Any textual value D. One of two values: True or False Answer: D. One of two values: True or False Rationale: Boolean values are logical values that can only be either true or false. --- QUESTION 17 Which statement correctly describes relational operators? A. Relational operators are a direct comparison of two values B. Relational operators give a Boolean result C. Relational operators are defined for all basic data types D. All of the above Answer: D. All of the above Answer: B. % Rationale: The modulo operator (%) returns the remainder of division. If `number % 5 == 0`, the number is evenly divisible by 5. --- QUESTION 20 A variable should hold the names of all past U.S. presidents. Which data type should the variable be? A. String B. Integer C. String array D. Boolean Answer: C. String array Rationale: An array of strings is appropriate for storing multiple text values like names. --- QUESTION 21 What is the loop expression in the following pseudocode?i = 0
while i < 20 Put i to output i = i + 1
A. i B. i < 20 C. i = 0 D. i = i + 1 Answer: B. i < 20 Rationale: The loop expression is the condition evaluated each iteration to determine whether the loop should continue executing. --- QUESTION 22 What is the loop variable initialization in the following pseudocode?y = 0 s = 100. while y < 10 s = s + (s 5.0) y = y + 1
## QUESTION 24 What does the following algorithm determine?if x == y z = 1 else z = 0
A. Whether x and y are the same B. Whether x and y are negative C. Whether x is 1 D. Whether x is 0 Answer: A. Whether x and y are the same Rationale: The algorithm sets z to 1 if x equals y, and 0 otherwise, indicating whether the two values are identical. --- QUESTION 25 What does an output of 1 indicate for the following algorithm running on a five-element list of integers?i = 0
x = 0 while i < 5 if list[i] < 0 x = 1 i = i + 1 Put x to output
A. All integers are positive. B. All integers are negative. C. At least one integer is negative. D. At least one integer is positive. Answer: C. At least one integer is negative Rationale: The algorithm sets x to 1 if any element in the list is negative, then outputs x. --- SECTION 2: FUNCTIONS AND MODULARIZATION (Questions 26-40) --- QUESTION 26 What is a parameter in a function? ## QUESTION 28 A function that returns no value is often called: A. Void function B. Procedure C. Both A and B D. Null function Answer: C. Both A and B Rationale: Functions that don't return values are often called void functions (in C-style languages) or procedures (in other languages). --- QUESTION 29 A function stub is: A. A completed function B. A function definition whose statements have not yet been written C. A function with too many parameters D. A recursive function Answer: B. A function definition whose statements have not yet been written Rationale: A function stub provides the function signature and return statement but contains placeholder code to be completed later. ## QUESTION 30 What is function overloading? A. Breaking code B. Multiple functions with the same name but different parameters C. Too many variables D. Recursion Answer: B. Multiple functions with the same name but different parameters Rationale: Function overloading allows multiple functions with the same name but different parameter lists to coexist, with the compiler selecting the appropriate one based on arguments . --- QUESTION 31 What is a base case in recursion? A. The first function call B. A condition that stops the recursion C. The main function D. A loop in the function