Docsity

WGU E010 Foundations of Programming (Python) | Comprehensive OA Practice Workbook | 162 Qu, Exams of Database Programming

Toggle sidebar
bg1
WGU E010 Foundations of Programming
(Python) | Comprehensive OA Practice
Workbook | 162 Questions, Coding
Exercises, Answers & Explanations |
2026/2027 Updated
Section 1: Python Fundamentals, Syntax & Data Types (Questions 1–
40)
1. Which symbol begins a single-line comment in Python?
A. //
B. #
C. /* */
D. --
Answer: B
Rationale: Python uses the hash symbol #. Everything after # on that line is
ignored by the interpreter.
2. After x = 42, what does type(x) return?
A. float
B. int
C. str
D. bool
Answer: B
Rationale: An unquoted whole number literal is stored as an int. type() reports the
dynamic type of the object bound to the name.
3. Which of the following is a legal Python variable name?
A. 2nd_value
B. my-value
C. class
D. _total_count
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

Partial preview of the text

Download WGU E010 Foundations of Programming (Python) | Comprehensive OA Practice Workbook | 162 Qu and more Exams Database Programming in PDF only on Docsity!

WGU E010 Foundations of Programming

(Python) | Comprehensive OA Practice

Workbook | 162 Questions, Coding

Exercises, Answers & Explanations |

2026/2027 Updated

Section 1: Python Fundamentals, Syntax & Data Types (Questions 1–

1. Which symbol begins a single-line comment in Python? A. // B. # C. /* */ D. -- Answer: B Rationale: Python uses the hash symbol #. Everything after # on that line is ignored by the interpreter. 2. After x = 42 , what does type(x) return? A. float B. int C. str D. bool Answer: B Rationale: An unquoted whole number literal is stored as an int. type() reports the dynamic type of the object bound to the name. 3. Which of the following is a legal Python variable name? A. 2nd_value B. my-value C. class D. _total_count

Answer: D Rationale: Identifiers may start with a letter or underscore and contain letters, digits, and underscores. They cannot start with a digit or be a reserved keyword.

4. What is the data type of 3.14? A. int B. float C. str D. decimal Answer: B Rationale: A numeric literal containing a decimal point is a floating-point number (float). 5. What does print("Hello") display? A. "Hello" including quotes B. Hello without quotes C. print("Hello") D. Syntax error Answer: B Rationale: The print function outputs the evaluated string value; the quotes are delimiters in source code and do not appear in output. 6. Python is described as dynamically typed. This means: A. Every variable must have a type annotation B. Variables are locked to their first type C. The type of a name is determined by the object it currently references and can change D. Type checking occurs only at compile time Answer: C Rationale: Names are bindings to objects. The type belongs to the object, not the name, so the same name may later refer to a different type of object. 7. What is the result of 10 / 2 in Python 3? A. 5 (int) B. 5.0 (float)

C. !=

D. ===

Answer: B Rationale: == is the equality comparison operator. = is assignment. != means not equal. === is not valid in Python.

12. What does bool([]) return? A. True B. False C. None D. Error Answer: B Rationale: Empty containers (list, dict, set, tuple, empty string) evaluate to False in a boolean context. 13. What does bool("") return? A. True B. False C. None D. Error Answer: B Rationale: Empty strings are falsy in Python. A string containing any characters (even "False") is truthy. 14. Which correctly converts the string "123" to an integer? A. integer("123") B. int("123") C. str(123) D. float("123") Answer: B Rationale: int() converts a string (or float) to an integer. str() converts to string, float() to floating point. 15. What is the output of print(type(10 / 2))? A.

B. C. D. Answer: B Rationale: Division / always returns a float in Python 3, so 10 / 2 = 5.0, type is float.

16. Which data type is immutable? A. list B. dict C. set D. tuple Answer: D Rationale: Tuples cannot be changed after creation. Lists, dictionaries, and sets are mutable. 17. What is the value of x after x = 4 + 3 * 2? A. 14 B. 10 C. 11 D. 7 Answer: B Rationale: Multiplication before addition: 3 * 2 = 6, then 4 + 6 = 10. 18. Which data type stores whole numbers? A. float B. str C. int D. bool Answer: C Rationale: Integers (int) represent whole numbers without decimal points. 19. What does print(5 > 3 and 2 < 1) output? A. True B. False

C. 2.

D. 1

Answer: B Rationale: Floor division // returns the integer quotient, discarding remainder. 5 // 2 = 2.

24. What does the input() function return when a user types 42? A. int B. float C. str D. bool Answer: C Rationale: input() always returns a string; explicit conversion (e.g., int(input())) is required for numeric operations. 25. What is the output of print(type(10))? A. int B. C. number D. integer Answer: B Rationale: type() returns the type object; printing it displays . 26. Which operator is used for string repetition? A. + B. * C. % D. // Answer: B Rationale: "5" * 2 produces "55" through string replication. 27. What is the result of "5" * 2? A. 10 B. "55"

C. Error D. "10" Answer: B Rationale: When a string is multiplied by an integer, Python repeats the string that many times.

28. What is the data type of True? A. int B. str C. bool D. float Answer: C Rationale: Boolean literals True and False are the only values of type bool. Quoting them creates a string; using 1 creates an integer. 29. Which of the following evaluates to True when passed to bool()? A. 0 B. "" C. [] D. "[False]" Answer: D Rationale: A non-empty string (even one spelling "False") evaluates to True. Numeric zeros and empty containers are falsy. 30. What is the output of print(2 * 3 ** 2)? A. 36 B. 18 C. 12 D. 64 Answer: B Rationale: Exponentiation has higher precedence than multiplication: 3 ** 2 = 9, then 2 * 9 = 18. 31. Which of the following is a Python keyword? A. print

C. Variable names are case-insensitive D. Variable names can start with a digit Answer: B Rationale: Python is dynamically typed; a name can be rebound to an object of a different type.

36. What is the output of print("Python"[0])? A. P B. y C. n D. 0 Answer: A Rationale: String indexing starts at 0; index 0 is the first character P. 37. Which of the following is a valid integer literal? A. 3. B. "3" C. 3 D. 3. Answer: C Rationale: An unquoted whole number without a decimal point is an int literal. 38. What does print(True + True) output? A. True B. 2 C. Error D. False Answer: B Rationale: In Python, True evaluates to 1 in numeric contexts, so 1 + 1 = 2. 39. What is the result of not True? A. True B. False C. None D. Error

Answer: B Rationale: The not operator negates a boolean value.

40. Which of the following is the correct way to assign multiple variables in one line? A. x, y = 1, 2 B. x = 1, y = 2 C. x and y = 1, 2 D. x; y = 1; 2 Answer: A Rationale: Python supports tuple unpacking: x, y = 1, 2 assigns 1 to x and 2 to y. **Section 2: Control Flow — Conditionals & Loops (Questions 41–70)

  1. Which loop is best when the number of iterations is unknown?** A. for loop B. while loop C. Nested loop D. foreach loop Answer: B Rationale: while loops run until a condition becomes false, ideal when iteration count is not known in advance. 42. What does the break statement do? A. Skips one iteration B. Exits the loop completely C. Restarts the loop D. Stops the program Answer: B Rationale: break immediately terminates the loop. 43. What punctuation must follow an if statement line? A. Period B. Semicolon

Answer: A Rationale: range(3) produces 0, 1, 2.

48. What does the continue statement do? A. Exits the loop B. Skips the rest of the current iteration and moves to the next C. Restarts the loop from the beginning D. Stops the program Answer: B Rationale: continue skips remaining code in the current iteration and proceeds to the next. 49. How many times does this loop run? for i in range(5): print(i) A. 4 B. 5 C. 6 D. 0 Answer: B Rationale: range(5) produces 0, 1, 2, 3, 4 — five iterations. 50. What is the output of: x = 5 then if x > 3: print("A") else: print("B")? A. A B. B C. AB D. Error Answer: A Rationale: 5 > 3 is True, so the if block executes. 51. In a while loop, what must eventually happen to avoid an infinite loop? A. The condition must become False B. The loop must contain a print statement C. The loop must contain a break at the end D. The loop must use range()

Answer: A Rationale: A while loop continues while its condition is True; without the condition becoming False (or a break), it runs infinitely.

52. What is the output of: for i in range(1, 4): print(i * 2)? A. 2 4 6 B. 1 2 3 C. 2 4 D. 1 3 5 Answer: A Rationale: range(1, 4) produces 1, 2, 3. Multiplying each by 2 gives 2, 4, 6. 53. Which of the following correctly checks if x is between 1 and 10 (inclusive)? A. if x >= 1 and x <= 10: B. if x >= 1 or x <= 10: C. if 1 < x < 10: D. if x in range(1, 11): Answer: A Rationale: Both conditions must be true for the value to be between 1 and 10 inclusive. 54. What is the output of: x = 0 then while x < 3: print(x); x += 1? A. 0 1 2 B. 1 2 3 C. 0 1 2 3 D. Infinite loop Answer: A Rationale: The loop runs for x = 0, 1, 2, printing each before incrementing. 55. What is the result of range(10, 0, - 2)? A. 10, 8, 6, 4, 2 B. 10, 9, 8, ..., 1 C. 0, 2, 4, 6, 8, 10 D. 10, 8, 6, 4, 2, 0

Answer: C Rationale: Python has no do-while loop; while and for are the only loop constructs.

60. What does range(5, 5) produce? A. [5] B. [] (empty) C. [0, 1, 2, 3, 4] D. Error Answer: B Rationale: range(5, 5) produces an empty sequence because the start equals the stop. 61. What is the output of: x = 3 then if x == 3: print("Three")? A. Three B. Nothing C. x D. Error Answer: A Rationale: 3 == 3 is True, so the print executes. 62. Which operator is used for logical AND? A. & B. && C. and D. AND Answer: C Rationale: Python uses the word and for logical conjunction. 63. What is the output of: print(True and False)? A. True B. False C. None D. Error

Answer: B Rationale: and returns True only when both operands are True.

64. What is the output of: print(True or False)? A. True B. False C. None D. Error Answer: A Rationale: or returns True when at least one operand is True. 65. What is the output of: for i in range(5): if i == 3: break then print(i)? A. 3 B. 4 C. 2 D. 0 Answer: A Rationale: The loop breaks when i == 3, so i retains the value 3 after the loop. 66. What is the output of: for i in range(5): if i == 3: continue then print(i) after loop? A. 4 B. 3 C. 5 D. 0 Answer: A Rationale: continue skips printing when i == 3, but the loop continues to i = 4, which is the last value. 67. Which of the following creates an infinite loop? A. while True: B. while False: C. for i in range(0): D. for i in []:

C. define myFunc(): D. func myFunc(): Answer: B Rationale: Python uses def to define functions.

72. What is the output of: def add(x, y=5): return x + y then print(add(3))? A. 8 B. 3 C. 5 D. Error Answer: A Rationale: Default parameter y=5 is used when not provided: 3 + 5 = 8. 73. What does a function return if it has no return statement? A. 0 B. None C. Empty string D. Error Answer: B Rationale: Python functions implicitly return None if no return statement is executed. 74. Which statement about default arguments is correct? A. Default arguments are re-evaluated on every call B. Default arguments are evaluated once at function definition; mutable defaults persist across calls C. Default arguments must be mutable D. Default arguments are evaluated at module import only if the function is called Answer: B Rationale: Python evaluates default argument expressions once when the def statement executes. A mutable default (e.g., a list) is shared across calls, a classic bug source.

75. Write a function calculate_discount(price, discount_percent) that returns the final price after applying a discount. Example: calculate_discount(75, 20) should return 60. 0. Answer: python def calculate_discount(price, discount_percent): return price * ( 1 - discount_percent / 100 ) Rationale: Convert percentage to decimal, subtract from 1 to get remaining percentage, multiply by original price. 76. Write a function word_count(text) that returns the number of words in a string separated by spaces. Example: word_count("Hello world Python") should return 3. Answer: python def word_count(text): return len(text.split()) Rationale: .split() divides the string into a list of words, len() counts them. 77. Fix the function that should return the last character of a string: def get_last_character(text): return text[len(text)] Answer: python def get_last_character(text): return text[- 1 ] Rationale: Python indexing starts at 0. The last valid index is len(text) - 1 , or - 1 via negative indexing. 78. What is the scope of a variable defined inside a function? A. Global