
































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!

































Title: WGU E010 Foundations of Programming (Python) — Comprehensive OA Study Guide: 1,000+ Questions with Detailed Answer Explanations, Code Tracing Exercises, and Exam-Aligned Rationales (Updated Edition) About This Guide: This study guide contains 1,000+ original multiple-choice practice questions covering all chapters and competency areas of the WGU E010 Foundations of Programming (Python) course. Each question includes the correct answer immediately followed by a detailed explanation. Questions are numbered sequentially from 1 to the final question across all chapters. The content is aligned with WGU's published course competencies: identifying Python programming constructs, executing Python code, manipulating data structures, and creating functional programs. How to Use This Guide: Work through each chapter sequentially, or focus on chapters where you need the most practice. Cover the answer and explanation before attempting each question to simulate exam conditions. Code-tracing questions are designed to mirror the style of the E010 Objective Assessment. Note on Originality: All questions in this guide are original works created for study purposes. They are aligned with publicly available WGU course descriptions and competency statements but do not reproduce any proprietary assessment content.
Question 1: Which of the following is the correct file extension for a Python source code file? A. .java B. .py C. .python D. .pt Answer: B Explanation: Python source files use the .py extension. The .java extension is used for Java files, .python is not a standard extension, and .pt is commonly associated with PyTorch model files, not Python source code. Question 2: What is the primary purpose of indentation in Python? A. It makes code run faster B. It defines the structure and hierarchy of code blocks C. It is optional and only for readability D. It declares variable types Answer: B Explanation: Unlike many languages that use braces {} to define code blocks, Python uses indentation to determine the grouping of statements. Indentation defines which statements belong to a block, such as the body of a function, loop, or conditional. Incorrect indentation causes IndentationError. Question 3: Which of the following is a valid Python comment? A. // This is a comment B. /* This is a comment */
Answer: B Explanation: Jupyter Notebook is an interactive web-based environment that allows users to create and share documents containing live code, equations, visualizations, and narrative text. While VS Code and PyCharm are excellent Python IDEs, Jupyter is specifically designed for interactive and data science workflows. Question 6: What is the correct way to assign the value 10 to a variable named x in Python? A. int x = 10 B. x := 10 C. x = 10 D. let x = 10 Answer: C Explanation: Python uses the = operator for assignment. int x = 10 is C/Java syntax, x := 10 is the walrus operator (used in expressions, not simple assignment), and let x = 10 is JavaScript syntax. Question 7: What does the print() function do in Python? A. Reads input from the user B. Displays output to the console C. Writes data to a file D. Returns a value from a function Answer: B Explanation: The print() function outputs its arguments to the standard output (usually the console). Input is read using input(), file writing uses file methods like write(), and values are returned using the return statement.
Question 8: Which of the following is a valid variable name in Python? A. 2nd_place B. total-score C. _count D. class Answer: C Explanation: Variable names can start with a letter or underscore, followed by letters, digits, or underscores. 2nd_place starts with a digit (invalid), total-score contains a hyphen (invalid), and class is a reserved keyword (invalid). Question 9: What is the output of print(type(3.14))? A. B. C. D. Answer: B Explanation: In Python, numbers with decimal points are of type float. The type() function returns the class of the object. Python does not have a separate double type; all floating-point numbers are float. Question 10: What is the purpose of the input() function in Python? A. To display output to the screen B. To read a line of text from the user C. To read a file from disk D. To validate user input
allows for interactive execution and rapid development. Compiled languages like C convert all code before execution. Question 13: What is the output of print(10 % 3)? A. 3 B. 1 C. 0 D. 3. Answer: B Explanation: The % operator returns the remainder of division. 10 % 3 is 1 because 3 goes into 10 three times (9) with a remainder of 1. This operator is commonly used to check divisibility and in cyclic operations. Question 14: Which of the following is NOT a valid Python data type? A. int B. float C. char D. bool Answer: C Explanation: Python does not have a separate char type. Single characters are represented as strings of length 1 (e.g., 'a'). The other options — int, float, and bool — are all built-in Python types. Question 15: What will be the output of the following code? python print(bool( 0 )) print(bool(""))
print(bool([])) A. False, False, False B. True, True, True C. False, True, False D. True, False, True Answer: A Explanation: In Python, 0 , empty strings "", and empty collections like [] are all considered "falsy" values and evaluate to False when converted to boolean. Non-zero numbers and non-empty collections are "truthy." Question 16: What is the correct way to declare a string literal in Python? A. "Hello" or 'Hello' B. {Hello} C. D. (Hello) Answer: A Explanation: Python strings can be enclosed in single quotes ('Hello') or double quotes ("Hello"). Curly braces create sets or dictionaries, angle brackets are not used for strings, and parentheses create tuples or grouping expressions. Question 17: What is the output of print(len("Python"))? A. 5 B. 6 C. 7 D. Error
Question 20: What is the purpose of the type() function in Python? A. To convert a value from one type to another B. To return the data type of an object C. To check if a variable is defined D. To declare a variable's type Answer: B Explanation: The type() function returns the class/type of the given object. For example, type(5) returns . Type conversion is done with functions like int(), str(), and float(). Question 21: What will be the output of the following code? python x = 10 x += 5 print(x) A. 5 B. 10 C. 15 D. 105 Answer: C Explanation: The += operator is an augmented assignment operator. x += 5 is equivalent to x = x + 5. So 10 + 5 = 15. Question 22: Which of the following is true about Python variable declaration? A. Variables must be declared with a type before use B. Variables are dynamically typed
C. Variables cannot change type after assignment D. Variables must be declared with var Answer: B Explanation: Python is dynamically typed, meaning you don't declare a variable's type explicitly. The type is inferred at runtime from the assigned value, and a variable can be reassigned to a value of a different type later. Question 23: What is the output of print("5" * 3)? A. 15 B. 555 C. "555" D. Error Answer: B Explanation: In Python, multiplying a string by an integer repeats the string. "5" * 3 produces "555". This is string repetition, not arithmetic multiplication. Question 24: Which of the following correctly reads a user's name and stores it in a variable? A. name = input("Enter your name: ") B. name = get("Enter your name: ") C. input("Enter your name: ") = name D. name = read("Enter your name: ") Answer: A Explanation: The input() function reads user input and returns it as a string. The prompt string is optional. Assignment stores the returned string in the variable name. The other options use invalid functions or reversed assignment.
C. loop D. break Answer: C Explanation: while, for, and break are all Python reserved keywords. loop is not a keyword; it can be used as a variable name. Keywords cannot be used as identifiers. Question 28: What will be the output of the following code? python a = 5 b = 2 print(a / b) A. 2 B. 2. C. 3 D. 2. Answer: B Explanation: The / operator in Python 3 performs true division and always returns a float, even if the result is a whole number. 5 / 2 = 2.5. Use // for floor division if an integer result is desired. Question 29: What does the str() function do? A. Returns the length of a string B. Converts a value to a string C. Checks if a value is a string D. Reverses a string Answer: B Explanation: The str() function converts its argument to a string. For example, str(42)
returns "42". This is useful when concatenating numbers with strings or when printing mixed-type data. Question 30: Which of the following is a valid way to create a multi-line string in Python? A. "Line 1\nLine 2" B. """Line 1 Line 2""" C. 'Line 1' + '\n' + 'Line 2' D. All of the above Answer: D Explanation: All three approaches create multi-line strings. \n is a newline escape character. Triple-quoted strings preserve actual line breaks. String concatenation with '\n' also works. Triple quotes are most commonly used for docstrings and multi-line text. Question 31: What is the output of print(not True)? A. True B. False C. None D. Error Answer: B Explanation: The not operator is a logical negation operator. not True evaluates to False. Similarly, not False evaluates to True. Question 32: What will the following code output? python
C. o D. Error Answer: A Explanation: Strings in Python are sequences, and indexing starts at 0. So x[0] returns the first character, which is 'H'. x[1] would return 'e', and x[-1] would return 'o'. Question 35: Which of the following is the correct way to write a docstring for a function? A. # This function adds two numbers B. /* This function adds two numbers */ C. """This function adds two numbers.""" D. // This function adds two numbers Answer: C Explanation: A docstring is a string literal that appears as the first statement in a function, module, or class. Triple quotes are conventionally used. Docstrings can be accessed with help() or the doc attribute. Question 36: What will the following code print? python print( 3 * "abc") A. abcabcabc B. abc C. Error D. 3abc Answer: A Explanation: Multiplying a string by an integer repeats the string that many times. 3 *
"abc" produces "abcabcabc". The integer can come before or after the string; "abc" * 3 gives the same result. Question 37: What is the output of print(10 // 3)? A. 3. B. 3 C. 4 D. 3. Answer: B Explanation: Floor division // returns the largest integer less than or equal to the division result. 10 // 3 = 3 because 3.33 rounded down is 3. The result is an integer when both operands are integers. Question 38: Which of the following statements about Python's print() function is correct? A. It can only print one argument at a time B. It automatically adds a newline at the end by default C. It cannot print variables D. It returns the printed string Answer: B Explanation: The print() function adds a newline (\n) at the end by default. This can be changed with the end parameter. print() can take multiple arguments, separated by commas, and can print variables of any type. Question 39: What will be the output of the following code? python x = 5 print(type(x))
Answer: B Explanation: The and operator returns True only if both operands are True. Since b is False, the result is False. Python uses short-circuit evaluation: if the first operand is False, the second is not evaluated. Question 42: Which of the following best describes a Python module? A. A single Python function B. A file containing Python code that can be imported C. A Python class D. A variable Answer: B Explanation: A module is a .py file containing Python definitions and statements. Modules allow code organization and reuse. They are imported using the import statement. A module can contain functions, classes, and variables. Question 43: What is the output of print(abs(-7))? A. - B. 7 C. 0 D. Error Answer: B Explanation: The abs() function returns the absolute value of a number. abs(-7) returns
print(round(3.7)) A. 3 B. 4 C. 3. D. Error Answer: B Explanation: The round() function rounds a number to the nearest integer. 3.7 rounds to 4. Python uses banker's rounding (round half to even) for .5 cases, but 3.7 is clearly closer to 4. Question 45: Which of the following is a valid Python identifier? A. _my_var B. 2myvar C. my-var D. my var Answer: A Explanation: Python identifiers can contain letters, digits, and underscores, but cannot start with a digit or contain hyphens or spaces. _my_var is valid. 2myvar starts with a digit, my-var contains a hyphen, and my var contains a space. Question 46: What is the output of print("Python"[1:4])? A. Pyt B. yth C. ytho D. tho