Docsity

WGU E010 Foundations of Programming (Python) — Complete Objective Assessment Study Guide 1, Exams of Nursing

Toggle sidebar
bg1
WGU E010 Foundations of Programming
(Python) — Complete Objective Assessment
Study Guide
1,000+ Questions with Verified Answers and
Detailed Explanations | Updated Edition | All
Chapters Included
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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download WGU E010 Foundations of Programming (Python) — Complete Objective Assessment Study Guide 1 and more Exams Nursing in PDF only on Docsity!

WGU E010 Foundations of Programming

(Python) — Complete Objective Assessment

Study Guide

1,000+ Questions with Verified Answers and

Detailed Explanations | Updated Edition | All

Chapters Included

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 E 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.

CHAPTER 1: PYTHON BASICS, SYNTAX, AND

DEVELOPMENT ENVIRONMENTS

Questions 1–

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.

A. Eclipse B. Jupyter Notebook C. Visual Studio Code D. PyCharm 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?

C. A program that compiles Python to C D. A program that formats Python code Answer: B Explanation: Python is an interpreted language. The interpreter reads and executes code line by line, rather than compiling the entire program to machine code first. This 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.

A. 53

B. 8

C. "53"

D. Error Answer: B Explanation: The int() function converts the string "5" to the integer 5. Then 5 + 3 equals 8. Without the conversion, "5" + 3 would raise a TypeError because Python cannot concatenate a string and an integer. 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.

A. 64

B. 512

C. 12

D. 36

Answer: B Explanation: The exponentiation operator ** is right-associative. So 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512, not (2 ** 3) ** 2 = 64. Question 27: Which of the following is NOT a Python keyword? A. while B. for 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.

C. Returns the absolute value of a number D. Checks if a number has a decimal point Answer: A Explanation: The float() function converts an integer or string to a floating- point number. For example, float(5) returns 5.0 and float("3.14") returns 3.14. It does not round or take absolute values. Question 34: What will be the output of the following code? python x = "Hello" print(x[ 0 ]) A. H B. e 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?

Answer: B Explanation: == is the equality comparison operator. = is the assignment operator. === is strict equality in JavaScript, not Python. != checks for inequality. Question 41: What will the following code output? python a = True b = False print(a and b) A. True B. False C. None D. Error 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 7. The absolute value is the non-negative value of a number without regard to its sign. Question 44: What will the following code print? python 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. cases, but 3.7 is clearly closer to 4. Question 45: Which of the following is a valid Python identifier?