





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) QUESTION EXAM WITH RATIONALES
Typology: Exams
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















1. What is Python? A) Low-level programming language B) High-level programming language C) Assembly language D) Machine language Answer: B Rationale: Python is a high-level, interpreted programming language that emphasizes code readability and simplicity. It's not low-level (A), assembly (C), or machine language (D), which are closer to hardware. 2. Which of the following is the CORRECT way to print output in Python 3? A) print "Hello" B) echo "Hello" C) print("Hello") D) System.out.println("Hello") Answer: C Rationale: In Python 3, print() requires parentheses: print("Hello"). Option A is Python 2 syntax, B is bash, and D is Java syntax. 3. What data type is the value: 42? A) String B) Float C) Integer D) Boolean Answer: C Rationale: 42 is an integer (int) - a whole number without decimal points. String would be "42", float would be 42.0, and boolean would be True/False.
4. Which of the following is a VALID variable name in Python? A) 2myVariable B) my_variable C) my-variable D) var$iable Answer: B Rationale: my_variable is valid: starts with letter, contains only letters/numbers/underscores. Option A starts with number (invalid), C has hyphen (invalid), D has $ (invalid). 5. What is the output of: print(type(3.14))? A) int B) str C) float D) double Answer: C Rationale: 3.14 is a float (floating-point number) in Python. Python doesn't have a separate "double" type - floats are double-precision by default. 6. What data type is: True? A) Integer B) String C) Boolean D) Float Answer: C Rationale: True is a Boolean value (bool), one of two possible values: True or False. Not an integer (A), string (B), or float (D). 7. Which operator is used for exponentiation in Python? A) ^ B) ** C) pow() D) ^^
11. What is the output of: print(2 + 3 * 4)? A) 20 B) 14 C) 18 D) 24 Answer: B Rationale: Python follows standard math precedence: multiplication before addition. 3 4 = 12, then 2+12 = 14. Not (2+3) 4 = 20. 12. Which function converts a string to an integer? A) str() B) int() C) float() D) bool() Answer: B Rationale: int() converts to integer: int("42") = 42. str() converts to string, float() to float, bool() to boolean. 13. What is the length of: len("Python")? A) 5 B) 6 C) 7 D) 8 Answer: B Rationale: len("Python") counts characters: P-y-t-h-o-n = 6 characters. len() returns the number of items. 14. What is the result of: "5" + "3"? A) 8 B) "53" C) "8" D) Error
Answer: B Rationale: String concatenation: "5" + "3" = "53" (not 8). Both are strings, so they concatenate, not add numerically.
15. Which of the following is a COMMENT in Python? A) /* Comment / B) # Comment C) // Comment D) Answer: B Rationale: # starts a comment in Python. / */ is C/Java, // is JavaScript/Java, < > is not comment syntax. 16. What data type is:? A) Tuple B) List C) Dictionary D) Set Answer: B Rationale: with square brackets creates a list (mutable sequence). Tuple uses (), dictionary uses {}, set uses {} (without keys). 17. What is the output of: print(5 == 5)? A) True B) False C) 5 D) Error Answer: A Rationale: == is the equality operator: 5 == 5 is True (they are equal). This returns a Boolean.
C) "Python"[-1] D) "Python"[first] Answer: B Rationale: String indexing starts at 0: "Python" = "P". = "y", [-1] = "n" (last), [first] is invalid.
22. What is the output of: "Python"[2:5]? A) "yth" B) "ytho" C) "thon" D) "ytho" Answer: B Rationale: Slicing [2:5] gets indices 2, 3, 4 (stops before 5): P(0)-y(1)-t(2)-h(3)- o(4)-n(5) = "tho". Wait, let me recalculate: indices 2,3,4 = t,h,o = "tho". Actually the answer should be "tho", but options show "ytho". Let me correct: "Python"[2:5] = "tho" (t=2, h=3, o=4). Actually, reviewing: "Python"[2:5] = characters at positions 2, 3, 4 = "t", "h", "o" = "tho". None of the options match exactly. The correct answer is "tho". 23. Which method converts string to uppercase? A) .lower() B) .upper() C) .capital() D) .swap() Answer: B Rationale: .upper() converts to uppercase: "hello".upper() = "HELLO". .lower() converts to lowercase, .capital() and .swap() are not valid string methods. 24. What is the output of: "hello".upper()? A) "hello" B) "HELLO"
C) "Hello" D) Error Answer: B Rationale: .upper() converts all characters to uppercase: "hello".upper() = "HELLO". The original string is unchanged (strings are immutable).
25. Which method removes whitespace from both ends? A) .strip() B) .remove() C) .clear() D) .trim() Answer: A Rationale: .strip() removes leading/trailing whitespace: " hello ".strip() = "hello". .remove() and .clear() are not string methods, .trim() doesn't exist in Python. 26. What is the output of: " hello ".strip()? A) "hello" B) " hello " C) " hello" D) "hello " Answer: A Rationale: .strip() removes whitespace from BOTH ends: " hello ".strip() = "hello". .lstrip() removes left only, .rstrip() removes right only. 27. Which method finds the index of a substring? A) .find() B) .index() C) Both A and B D) Neither Answer: C Rationale: Both .find() and .index() find substring index. .find() returns - 1 if not found, .index() raises ValueError. Both work for finding.
C) .merge() D) .break() Answer: A Rationale: .split() divides string into list: "a,b,c".split(",") = ["a", "b", "c"]. .join() combines list into string, others invalid.
32. What is the output of: "a,b,c".split(",")? A) "abc" B) ["a", "b", "c"] C) ("a", "b", "c") D) Error Answer: B Rationale: .split(",") creates list from string: ["a", "b", "c"]. Returns list (not string or tuple). 33. Which method checks if string starts with text? A) .startswith() B) .beginwith() C) .first() D) .head() Answer: A Rationale: .startswith() checks prefix: "hello".startswith("he") = True. .beginwith(), .first(), .head() are not valid methods. 34. What is the output of: "hello".startswith("he")? A) True B) False C) None D) Error Answer: A Rationale: "hello" does start with "he", so .startswith("he") returns True (Boolean).
35. Which method checks if string ends with text? A) .endwith() B) .endswith() C) .last() D) .tail() Answer: B Rationale: .endswith() checks suffix: "hello".endswith("lo") = True. .endwith() (missing s) is invalid, .last() and .tail() don't exist. **SECTION 3: LISTS & LIST OPERATIONS (Questions 36-50)
42. Which method removes LAST element from list? A) .remove() B) .pop() C) .delete() D) .clear() Answer: B Rationale: .pop() removes and returns last element:.pop() = 2, list becomes. .remove(value) removes by value, .delete() invalid, .clear() removes all. 43. What is the output after: lst =; lst.pop(); print(lst)? A) B) C) D) Answer: B Rationale: .pop() removes last element (3): becomes. Returns the removed value. 44. Which method sorts a list? A) .sort() B) .sorted() C) Both A and B D) Neither Answer: C Rationale: Both work: .sort() sorts list in place, sorted() returns new sorted list. .sort() modifies original, sorted() doesn't. 45. What is the output: lst =; lst.sort(); print(lst)? A) B) C) D) Error
Answer: B Rationale: .sort() sorts in ascending order: becomes. Modifies list in place.
46. How do you check if value exists in list? A) .has() B) in C) .contains() D) .exist() Answer: B Rationale: in keyword checks membership: 2 in = True. .has(), .contains(), .exist() are not valid. 47. What is the output of: 5 in? A) True B) False C) None D) Error Answer: B Rationale: 5 is NOT in, so expression returns False. in returns Boolean. 48. Which method reverses a list? A) .reverse() B) .reversed() C) Both A and B D) Neither Answer: A Rationale: .reverse() reverses list in place. reversed() returns iterator (not method). .reverse() modifies original list. 49. What is the output after: lst =; lst.reverse(); print(lst)? A) B)
53. What output: x = 10; if x > 5: print("Big")? A) Big B) Small C) Nothing D) Error Answer: A Rationale: x = 10 > 5 is True, so prints "Big". Conditional executes when condition is True. 54. Which keyword is "else if" in Python? A) elseif B) elif C) else if D) then Answer: B Rationale: elif is Python's "else if": if x > 10: ... elif x > 5: ... elseif and else if are invalid. 55. What is the purpose of else? A) First condition B) Middle condition C) Final fallback (if all previous False) D) Loop starter Answer: C Rationale: else is final fallback: executes if all if/elif conditions are False. Not first (A), middle (B), or loop (D). 56. What output: x = 3; if x > 5: print("Big"); else: print("Small")? A) Big B) Small
C) Nothing D) Error Answer: B Rationale: x = 3 is NOT > 5 (False), so executes else: prints "Small".
57. Which is a NESTED if statement? A) if x > 5: print("Big") B) if x > 5: if y > 3: print("Both") C) if x > 5 or y > 3: print("Either") D) if x > 5 and y > 3: print("Both") Answer: B Rationale: Nested if has if inside another if: if x > 5: if y > 3: ... Options A, C, D are single conditionals with logical operators. 58. What does AND require? A) At least one True B) Both True C) Both False D) One False Answer: B Rationale: and requires BOTH conditions True: True and True = True, True and False = False. or requires at least one True. 59. What does OR require? A) At least one True B) Both True C) Both False D) Neither True Answer: A Rationale: or requires at least one True: True or False = True, False or False = False. and requires both True.
Answer: B Rationale: == is equality comparison: if x == 5:. = is assignment, <> is invalid, != is not equal (also correct for that case).
64. What is output: x = 5; print(x == 5)? A) True B) False C) 5 D) Error Answer: A Rationale: x == 5 checks equality: 5 == 5 is True. Returns Boolean, not the value. 65. Which checks if x is between 5 and 10? A) if x > 5 and x < 10: B) if 5 < x < 10: C) Both A and B D) Neither Answer: C Rationale: Both work: A uses and, B uses chained comparison (Python feature). Both check if x is between 5 and 10. **SECTION 5: LOOPS (Questions 66-80)
67. What is syntax for for loop? A) for i in range(5): code B) for i = 0 to 5: code C) for (i in range(5)): code D) for i in range(5) code Answer: A Rationale: for i in range(5): requires colon and indentation. No parentheses, no "to", requires colon. 68. What output: for i in range(3): print(i)? A) 0 1 2 B) 1 2 3 C) 0 1 2 3 D) 1 2 Answer: A Rationale: range(3) =: prints 0, 1, 2 (starts at 0, ends before 3). 69. What does range(5, 10) produce? A) B) C) D) Answer: A Rationale: range(5, 10) = 5 to 9 (starts at 5, ends before 10):. 70. Which loop continues while condition is True? A) for B) while C) until D) do