Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) EXAMINATION REVIEW – 125 STUDY GUIDE, Exams of Computer Science

Toggle sidebar
bg1
1
WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON)
EXAMINATION REVIEW – 125 STUDY GUIDE – PRACTICE
QUESTIONS WITH DETAILED RATIONALES (LATEST EDITION)
Computer Science / Information Technology / Software
Engineering
Exam Summary :-
SECTION 1: PYTHON BASICS, VARIABLES & DATA TYPES (Q1–
25)
1. A programmer is creating a new variable in Python and
needs to store a whole number. Which built-in data type is
designed specifically for whole numbers without decimal
points?
A) float
B) str
C) int
D) bool
CORRECT ANSWER: C) int
RATIONALE: The int type represents integer values—whole
numbers without fractional parts. It is the standard data type for
counting and indexing operations in Python. WHY OTHERS ARE
NOT CORRECT: float (A) stores numbers with decimal points;
str (B) stores text sequences; bool (D) stores only True or False.
2. A developer writes the statement age == 25 intending to
create a variable. What is the actual effect of this
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

Partial preview of the text

Download WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) EXAMINATION REVIEW – 125 STUDY GUIDE and more Exams Computer Science in PDF only on Docsity!

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON)

EXAMINATION REVIEW – 125 STUDY GUIDE – PRACTICE

QUESTIONS WITH DETAILED RATIONALES (LATEST EDITION)

Computer Science / Information Technology / Software Engineering Exam Summary :- SECTION 1: PYTHON BASICS, VARIABLES & DATA TYPES (Q1– 25)

1. A programmer is creating a new variable in Python and needs to store a whole number. Which built-in data type is designed specifically for whole numbers without decimal points? A) float B) str C) int D) bool CORRECT ANSWER: C) int RATIONALE: The int type represents integer values—whole numbers without fractional parts. It is the standard data type for counting and indexing operations in Python. WHY OTHERS ARE NOT CORRECT: float (A) stores numbers with decimal points; str (B) stores text sequences; bool (D) stores only True or False. 2. A developer writes the statement age == 25 intending to create a variable. What is the actual effect of this

statement? A) It creates a variable named age with the value 25 B) It compares the variable age to 25 and evaluates to a Boolean result C) It raises a SyntaxError because == cannot be used outside a conditional D) It assigns 25 to age and then compares it CORRECT ANSWER: B) It compares the variable age to 25 and evaluates to a Boolean result RATIONALE: The == operator is the equality comparison operator in Python, not the assignment operator. It checks whether the left and right operands are equal and returns True or False. WHY OTHERS ARE NOT CORRECT: Assignment requires the single equals sign = (A, D); == is valid anywhere an expression is allowed and does not inherently raise a SyntaxError (C).

3. Which of the following is the correct syntax for creating a single-line comment in Python? A) // This is a comment B) # This is a comment C) /* This is a comment */ D) -- This is a comment CORRECT ANSWER: B) # This is a comment RATIONALE: Python uses the hash symbol # to begin a single- line comment. Everything after # on the same line is ignored by

CORRECT ANSWER: B) float RATIONALE: Numeric values containing a decimal point are represented as floating-point numbers (float) in Python. The presence of the decimal point distinguishes a float from an integer. WHY OTHERS ARE NOT CORRECT: int (A) represents whole numbers; str (C) represents text; complex (D) represents numbers with real and imaginary parts (e.g., 3 + 4j).

6. Which of the following is a valid variable name in Python? A) 2nd_place B) my-variable C) _count D) my variable CORRECT ANSWER: C) _count RATIONALE: Python variable names may begin with a letter or an underscore and may contain letters, digits, and underscores. _count satisfies these rules. WHY OTHERS ARE NOT CORRECT: 2nd_place (A) begins with a digit; my-variable (B) contains a hyphen, which is interpreted as subtraction; my variable (D) contains a space, which is not allowed. 7. A programmer writes print(type(10)). What is the output? A) int B) C) number D) integer

CORRECT ANSWER: B) RATIONALE: The type() function returns the class object of its argument, and its printed representation includes the angle brackets and quotes: . WHY OTHERS ARE NOT CORRECT: int (A) is the name of the type but not what print(type(10)) outputs; number (C) and integer (D) are not the actual output format.

8. What is the result of the expression 3 + 2 * 2 in Python? A) 10 B) 7 C) 8 D) 12 CORRECT ANSWER: B) 7 RATIONALE: Python follows the standard order of operations: multiplication before addition. Therefore, 2 * 2 = 4, and 3 + 4 = 7. WHY OTHERS ARE NOT CORRECT: 10 (A) would result from (3 +

    • 2; 8 (C) and 12 (D) do not follow from any standard grouping of these operands. 9. Which operator is used for exponentiation (raising a number to a power) in Python? A) ^ B) ** C) * D) //

empty string; "" (C) is the original value, not a Boolean; no error occurs (D is false).

12. What is the data type of the value "42" in Python? A) int B) float C) str D) bool CORRECT ANSWER: C) str RATIONALE: Values enclosed in quotation marks—whether single or double—are strings (str) in Python, even if they contain numeric characters. WHY OTHERS ARE NOT CORRECT: int (A) and float (B) require numeric literals without quotes; bool (D) requires True or False. 13. Which expression correctly converts the string "3.14" to a floating-point number? A) int("3.14") B) float("3.14") C) str("3.14") D) bool("3.14") CORRECT ANSWER: B) float("3.14") RATIONALE: The float() function parses a string containing a decimal number and returns the corresponding floating-point value. WHY OTHERS ARE NOT CORRECT: int("3.14") (A) raises a ValueError because int() cannot directly parse a decimal string; str() (C) returns the same string; bool() (D) returns True.

14. What is the result of int("3.14")? A) 3 B) 3. C) Error D) "3.14" CORRECT ANSWER: C) Error RATIONALE: The int() function cannot directly convert a string containing a decimal point to an integer. It raises a ValueError. To convert such a string, float() must be used first. WHY OTHERS ARE NOT CORRECT: 3 (A) would require truncation, which int() does not perform on strings with decimals; 3.14 (B) is a float, not an int; "3.14" (D) is the original string. 15. Which of the following is NOT a valid Python variable name? A) my_var B) myVar C) 2myVar D) my_var_ CORRECT ANSWER: C) 2myVar RATIONALE: Python variable names cannot begin with a digit. They must start with a letter or an underscore. 2myVar violates this rule. WHY OTHERS ARE NOT CORRECT: my_var (A), myVar (B), and my_var_2 (D) all begin with a letter and contain only valid characters.

C) %

D) **

CORRECT ANSWER: B) //

RATIONALE: The // operator performs floor division, dividing the left operand by the right and rounding down to the nearest integer. For example, 17 // 4 evaluates to 4. WHY OTHERS ARE NOT CORRECT: / (A) performs true division and returns a float; % (C) is the modulo operator (remainder); ** (D) is exponentiation.

19. What does the modulo operator % return? A) The quotient of division B) The remainder of division C) The exponentiation result D) The floor division result CORRECT ANSWER: B) The remainder of division RATIONALE: The % operator returns the remainder after division. For example, 5 % 2 evaluates to 1. WHY OTHERS ARE NOT CORRECT: The quotient (A) is returned by / or //; exponentiation (C) is ; floor division (D) is //. 20. Evaluate the expression 17 // 4 + 5 % 2. What is the final value?** A) 5 B) 5. C) 4 D) 6

CORRECT ANSWER: A) 5

RATIONALE: First, 17 // 4 evaluates to 4 (floor division). Then 5 % 2 evaluates to 1 (remainder). Finally, 4 + 1 = 5. WHY OTHERS ARE NOT CORRECT: 5.25 (B) would result from true division; 4 (C) and 6 (D) do not follow from the correct operator precedence and evaluation.

21. What is the result of len("Python")? A) 5 B) 6 C) 7 D) Error CORRECT ANSWER: B) 6 RATIONALE: The len() function returns the number of characters in a string. "Python" has six characters: P, y, t, h, o, n. WHY OTHERS ARE NOT CORRECT: 5 (A), 7 (C), and Error (D) do not match the character count. 22. Which of the following is NOT a Python keyword? A) if B) for C) value D) while CORRECT ANSWER: C) value RATIONALE: value is a normal identifier and is not a reserved keyword in Python. It can be used as a variable name. Keywords such as if, for, and while are reserved and cannot be used as

would apply to text; (D) is not a Python type name.

25. Which function is used to display output to the console in Python? A) input() B) print() C) display() D) write() CORRECT ANSWER: B) print() RATIONALE: The print() function sends text or other values to standard output (the console). It is the standard way to display output in Python. WHY OTHERS ARE NOT CORRECT: input() (A) reads input from the user; display() (C) is not a built-in Python function; write() (D) is a file method, not a console output function. **SECTION 2: CONTROL FLOW — CONDITIONALS & LOGICAL OPERATORS (Q26–50)

  1. A programmer writes** if x > 5: followed by an indented block. What does the indentation signify in Python? A) It is optional and only for readability B) It defines the block of code that executes when the condition is True C) It indicates a syntax error D) It marks the end of the program

CORRECT ANSWER: B) It defines the block of code that executes when the condition is True RATIONALE: Python uses indentation (whitespace at the beginning of a line) to define code blocks. The indented statements under an if statement constitute the body that executes only when the condition evaluates to True. WHY OTHERS ARE NOT CORRECT: Indentation is syntactically required in Python, not optional (A); inconsistent indentation can cause errors, but indentation itself is not an error (C); it does not mark the end of the program (D).

27. Which keyword is used in Python to specify an alternative block of code that executes when the if condition is False? A) elif B) else C) then D) otherwise CORRECT ANSWER: B) else RATIONALE: The else keyword introduces a block that executes when the preceding if (and any elif) conditions are False. It provides a default path. WHY OTHERS ARE NOT CORRECT: elif (A) introduces an additional condition to test; then (C) and otherwise (D) are not Python keywords. 28. A programmer needs to check multiple conditions in sequence, executing the first block whose condition is True. Which construct is most appropriate?

30. Which logical operator returns True only when both operands are True? A) or B) and C) not D) xor CORRECT ANSWER: B) and RATIONALE: The and operator evaluates to True only if both operands are truthy. If either operand is False, the result is False. WHY OTHERS ARE NOT CORRECT: or (A) returns True if at least one operand is True; not (C) negates a single operand; xor (D) is not a built-in Python logical operator (bitwise XOR is ^). 31. According to De Morgan's Laws, which expression is logically equivalent to not (x > 5 and y < 10)? A) x <= 5 or y >= 10 B) x < 5 or y > 10 C) x <= 5 and y >= 10 D) x > 5 or y < 10 CORRECT ANSWER: A) x <= 5 or y >= 10 RATIONALE: De Morgan's Laws state that not (A and B) is equivalent to not A or not B. Applying this: not (x > 5) becomes x <= 5, and not (y < 10) becomes y >= 10. The and becomes or, yielding x <= 5 or y >= 10. WHY OTHERS ARE NOT CORRECT: x < 5 (B) is incorrect because not (x > 5) includes x == 5; and (C)

violates De Morgan's transformation; the expression in (D) is the original inner condition, not its negation.

32. What is the output of the following code? python x = 15 if x > 10: print("Large") elif x > 5: print("Medium") else: print("Small") A) Large B) Medium C) Small D) Error CORRECT ANSWER: A) Large RATIONALE: The first condition x > 10 is True (15 > 10), so the if block executes and prints "Large". The elif and else blocks are skipped because a preceding condition was already satisfied. WHY OTHERS ARE NOT CORRECT: Medium (B) would print only if the first condition were False and the second True; Small (C) would print only if both conditions were False; no error occurs (D).

35. What is the output of print(5 > 3 and 2 > 4)? A) True B) False C) 5 D) Error CORRECT ANSWER: B) False RATIONALE: 5 > 3 is True, but 2 > 4 is False. The and operator returns True only when both operands are True. Since one operand is False, the result is False. WHY OTHERS ARE NOT CORRECT: True (A) would require both comparisons to be True; 5 (C) is not a Boolean result; no error occurs (D). 36. Which of the following is the correct syntax for an if statement in Python? A) if (x > 5) { print("Yes") } B) if x > 5: print("Yes") C) if x > 5 then print("Yes") D) if x > 5 do print("Yes") CORRECT ANSWER: B) if x > 5: print("Yes") RATIONALE: Python if statements require a colon : at the end of the condition line, followed by an indented block. Parentheses around the condition are optional. WHY OTHERS ARE NOT CORRECT: Curly braces (A) are used in languages like C and Java, not Python; then (C) and do (D) are not Python keywords for if statements.

37. In an if – elif – else chain, how many blocks can execute? A) Exactly one B) At most one C) At least one D) All of them CORRECT ANSWER: B) At most one RATIONALE: The if–elif–else chain evaluates conditions sequentially and executes the first block whose condition is True. Once a block executes, the remaining conditions are skipped. If no condition is True and an else exists, the else block executes. Therefore, at most one block executes. WHY OTHERS ARE NOT CORRECT: Exactly one (A) assumes an else is always present and a condition is always True; at least one (C) is not guaranteed if no else exists and all conditions are False; all of them (D) is impossible because execution stops after the first True condition. 38. What is the result of not True? A) True B) False C) 0 D) Error CORRECT ANSWER: B) False RATIONALE: The not operator negates a Boolean value: not True evaluates to False, and not False evaluates to True. WHY