


























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























































































This comprehensive study resource features 30 0 meticulously crafted multiple-choice questions designed to mirror the logic and syntax found on the WGU D335 Objective Assessment. Each question includes a detailed, italicized rationale to help you master core Python concepts such as string formatting, dictionary manipulation, and file I/O operations. Perfect for students aiming to pass the OA on their first attempt, this guide bridges the gap between ZyBooks practice labs and the final high-stakes exam. What is the result of 10 // 3 in Python? A) 3.3 3 B) 3 C) 4 D) 3. 0 Answer: B Rationale: The // operator performs floor division, which rounds the result down to the nearest whole integer. Which of the following is a mutable data type? A) Tuple B) String C) List D) Integer Answer: C Rationale: Lists can be modified after creation (adding/removing items), whereas tuples, strings, and integers are immutable. How do you start a function definition in Python? A) function myFunc(): B) define myFunc(): C) def myFunc(): D) func myFunc(): Answer: C Rationale: The def keyword is the standard Python syntax for defining a new function.
What is the output of print(type(5.0))? A) B) C) D) Answer: C Rationale: Any number containing a decimal point is treated as a float in Python. Which method is used to remove only trailing whitespace from a string? A) .strip() B) .lstrip() C) .rstrip() D) .remove() Answer: C Rationale: .rstrip() stands for "right strip," which removes whitespace from the end (right side) of a string. What will bool(0) evaluate to? A) True B) False C) None D) Error Answer: B Rationale: In Python, the integer 0, empty sequences, and None are all evaluated as False in a boolean context. Which operator is used for exponentiation (power)? A) ^ B) ** C) * D) exp() Answer: B Rationale: The double asterisk ** is used to raise a number to a power (e.g., 2 ** 3 = 8). What does the .split() method return by default? A) A string B) A tuple C) A list D) A dictionary Answer: C
C) Error D) ["Python", "Python"] Answer: A Rationale: Using the multiplication operator on a string performs string repetition. Which function converts a string to an integer? A) str() B) float() C) int() D) cast(int) Answer: C Rationale: int() is a built-in constructor that parses a string or float into an integer. What is the correct syntax for an if statement? A) if x > 5 then: B) if (x > 5) C) if x > 5: D) if x > 5; Answer: C Rationale: Python requires a colon : at the end of control flow statements like if, for, and while. Which of the following is used to read all lines of a file into a list? A) file.read() B) file.readline() C) file.readlines() D) file.list() Answer: C Rationale: .readlines() reads the entire file and returns a list where each element is a single line. What does the break keyword do? A) Skips the current iteration B) Exits the entire loop C) Restarts the loop D) Stops the whole program Answer: B Rationale: break provides an immediate exit from the innermost loop currently executing. What is the output of len(["apple", "banana", "cherry"])? A) 3
Answer: A Rationale: len() returns the number of items/elements within the list container. Which f-string formats a float x to 2 decimal places? A) f"{x.2f}" B) f"{x:2f}" C) f"{x:.2f}" D) f"{x:.2}" Answer: C Rationale: The syntax :.2f specifies a fixed-point notation with two digits following the decimal. Which operator checks if two values are equal? A) = B) == C) is D) != Answer: B Rationale: = is for assignment; == is the comparison operator used to check for equality of values. What is the output of range(5)? A) [1, 2, 3, 4, 5] B) 0, 1, 2, 3, 4 C) 0, 1, 2, 3, 4, 5 D) [0, 1, 2, 3, 4, 5] Answer: B Rationale: range(n) generates a sequence starting from 0 and stopping at n- 1. Which method returns a list of dictionary keys? A) .get_keys() B) .keys() C) .list_keys() D) .items() Answer: B Rationale: The .keys() method returns a view object containing all keys in the dictionary.
Answer: B Rationale: The import statement is used to bring external modules or libraries into your script. What is the default separator for the print() function? A) Comma B) Tab C) Space D) Newline Answer: C Rationale: By default, print(a, b) will place a single space between the two values. What is the output of 2 + 3 * 4? A) 2 0 B) 1 4 C) 1 2 D) 2 4 Answer: B Rationale: Python follows PEMDAS; multiplication (3 4=12) is performed before addition (12+2=14).* Which keyword is used to skip the rest of a loop's code and move to the next iteration? A) break B) pass C) continue D) skip Answer: C Rationale: continue stops the current loop cycle and jumps immediately to the start of the next one. What is a "docstring"? A) A string used to document a function/class B) A string that cannot be changed C) A string containing a file path D) A type of error Answer: A Rationale: Docstrings are literal strings placed at the start of a function to explain its purpose. What does my_list[-1] represent? A) The first element
B) The last element C) An error D) The second to last element Answer: B Rationale: Negative indexing starts from the end of a list, where - 1 is the very last item. What is the result of 10 > 5 and 5 > 10? A) True B) False C) None D) Error Answer: B Rationale: The and operator requires both conditions to be True. Since 5 > 10 is False, the whole statement is False. Which method converts all characters in a string to lowercase? A) .low() B) .small() C) .lower() D) .case_fold() Answer: C Rationale: .lower() is the standard method for converting string characters to lowercase. What is an "IndexError"? A) Using the wrong variable name B) Attempting to access a list index that is out of range C) Dividing by zero D) Using a float as a list index Answer: B Rationale: This error occurs when you try to access a position (like index 10) that doesn't exist in the list. How do you check if the key 'color' exists in car_dict? A) if 'color' in car_dict: B) if car_dict.has('color'): C) if 'color' exists in car_dict: D) if car_dict['color']: Answer: A Rationale: The in operator is the efficient, Pythonic way to check for the presence of a key in a dictionary.
Rationale: While .append() adds one item, .extend() takes an iterable (like another list) and adds all its items. What does id() return? A) The value of the object B) The data type of the object C) The unique memory address of the object D) The name of the variable Answer: C Rationale: Every object in Python has a unique identity (integer) representing its location in memory. How do you define a list? A) x = (1, 2) B) x = {1, 2} C) x = [1, 2] D) x = <1, 2> Answer: C Rationale: Square brackets [] are the syntax for list literals. What is the result of list(range(2, 8, 2))? A) [2, 3, 4, 5, 6, 7, 8] B) [2, 4, 6, 8] C) [2, 4, 6] D) [4, 6, 8] Answer: C Rationale: range(start, stop, step) starts at 2, increments by 2, and stops BEFORE 8. Which command line argument contains the script name? A) sys.argv[0] B) sys.argv[1] C) sys.args[0] D) os.argv[0] Answer: A Rationale: In the sys.argv list, index 0 is always the name of the Python script being executed. What is the output of "hello".capitalize()? A) HELLO B) Hello C) hello
Answer: B Rationale: .capitalize() makes the first character uppercase and the rest lowercase. What is the result of round(3.5)? A) 3 B) 4 C) 3. 0 D) 4. 0 Answer: B Rationale: Python's round() function rounds to the nearest even number if exactly at .5, but for positive floats like 3.5, it typically rounds to 4. Which of the following creates a comment? A) // comment B) /* comment */ C) # comment D) -- comment Answer: C Rationale: The # symbol is used for single-line comments in Python. How do you find the index of the first occurrence of "x" in a list? A) list.find("x") B) list.search("x") C) list.index("x") D) list.locate("x") Answer: C Rationale: The .index() method returns the position of the first matching element found. What is the correct mode to open a file for appending? A) 'r' B) 'w' C) 'a' D) 'x' Answer: C Rationale: The 'a' mode (append) adds data to the end of the file without overwriting existing content.
Correct Answer: C Rationale: Regardless of what the user types (even if it's a number), input() captures it as a string. What is the result of 2 ** 4? A. 8 B. 1 6 C. 6 D. 1 2 Correct Answer: B Rationale: The double asterisk (**) is the exponentiation operator. 2 to the 4th power is 16. Which of these is a valid variable name? A. 1st_name B. first-name C. first_name D. first name Correct Answer: C Rationale: Variable names cannot start with numbers, contain hyphens, or include spaces. Underscores are allowed. What is the output of 7 % 2? A. 3. 5 B. 3 C. 1 D. 0 Correct Answer: C Rationale: The modulo operator (%) returns the remainder. 7 divided by 2 is 3 with a remainder of 1. How do you add "blue" to the end of a list called colors? A. colors.add("blue") B. colors.insert("blue") C. colors.append("blue") D. colors.push("blue") Correct Answer: C Rationale: append() is the specific method used to add a single item to the end of an existing list. What is the value of x after x = 10; x += 5? A. 1 0
Correct Answer: C Rationale: The augmented assignment operator += adds the value to the variable and reassigns the result. Which operator is used to check if two values are equal? A. = B. is C. == D. != Correct Answer: C Rationale: == checks if the values of two objects are equal. What does range(3) produce when used in a loop? A. 1, 2, 3 B. 0, 1, 2 C. 0, 1, 2, 3 D. 1, 2 Correct Answer: B Rationale: range(n) starts at 0 and goes up to, but does not include, the number n. Which method converts a string to all lowercase? A. low() B. lowercase() C. lower() D. case_low() Correct Answer: C Rationale: The .lower() method returns a copy of the string with all characters in lowercase. How do you define a function in Python? A. function my_func(): B. def my_func(): C. define my_func(): D. sub my_func(): Correct Answer: B Rationale: The 'def' keyword is used to define functions in Python. What is the output of bool(0)? A. True
B. Python C. TypeError D. Py+thon Correct Answer: B Rationale: The + operator concatenates (joins) two strings together. Which block of code runs if an exception occurs? A. try B. except C. finally D. else Correct Answer: B Rationale: The except block is specifically designed to handle errors caught in the try block. What does math.ceil(2.1) return? A. 2 B. 2. 0 C. 3 D. 3. 0 Correct Answer: C Rationale: ceil (ceiling) always rounds a decimal up to the nearest whole integer. How do you check if "apple" is in the list fruits? A. if fruits.contains("apple"): B. if "apple" in fruits: C. if "apple" is fruits: D. if fruits == "apple": Correct Answer: B Rationale: The 'in' operator is the standard way to check for membership in a collection. What is the output of 3 * 'A'? A. 3A B. AAA C. A 3 D. Error Correct Answer: B Rationale: Multiplying a string by an integer repeats the string that number of times. Which method removes the last item from a list? A. remove() B. delete()
C. pop() D. clear() Correct Answer: C Rationale: pop() removes and returns the last item (or an item at a specific index). What is the result of 10 / 2? A. 5 B. 5. 0 C. 2 D. 2. 0 Correct Answer: B Rationale: Standard division (/) in Python 3 always returns a floating-point number. Which keyword is used to create a loop that iterates over a sequence? A. while B. loop C. for D. foreach Correct Answer: C Rationale: The 'for' loop is used to iterate over items in a list, string, or range. What does strip() do to a string? A. Capitalizes every word B. Removes leading and trailing whitespace C. Splits the string into a list D. Reverses the string Correct Answer: B Rationale: strip() is commonly used to clean up input by removing extra spaces or newlines at the ends. What is the correct syntax for a comment? A. // comment B. /* comment */ C. # comment D. -- comment Correct Answer: C Rationale: The hash (#) character starts a single-line comment in Python. What is the value of bool("")? A. True B. False C. None
Rationale: The 'sep' parameter in print() changes the character used to separate multiple arguments. Which statement is used to skip the rest of the code in the current iteration and move to the next? A. break B. continue C. pass D. skip Correct Answer: B Rationale: continue stops the current loop cycle and immediately jumps to the next evaluation. What is the result of len()? A. 2 B. 3 C. 4 D. 1 Correct Answer: B Rationale: len() counts the number of top-level items in the list. How do you import the math module? A. include math B. use math C. import math D. from math import all Correct Answer: C Rationale: 'import' followed by the module name is the standard syntax. What does split() do to a string? A. Joins words into one string B. Breaks a string into a list of words C. Removes punctuation D. Converts string to a tuple Correct Answer: B Rationale: By default, split() divides a string based on whitespace and returns a list. What is the output of 2 + 3 * 2? A. 1 0 B. 8 C. 7 D. 1 2
Correct Answer: B Rationale: Operator precedence ensures multiplication happens before addition (3 * 2 = 6; 2 + 6 = 8). Which method finds the index of a value in a list? A. find() B. search() C. index() D. get() Correct Answer: C Rationale: index() returns the position of the first occurrence of a value. What is the result of not (5 > 2)? A. True B. False C. 5 D. 2 Correct Answer: B Rationale: 5 > 2 is True; the 'not' operator flips it to False. How do you define an empty list? A. list = {} B. list = [] C. list = () D. list = "" Correct Answer: B Rationale: Square brackets indicate a list; empty ones create an empty list. What is a "docstring"? A. A string that defines a variable B. A comment used to describe a function or class C. A string that is printed to the console D. A specific type of list Correct Answer: B Rationale: Docstrings are string literals appearing right after a function/class definition to document it. What does round(3.5) return? A. 3 B. 4 C. 3. 5 D. 3. 0