
































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!

































This question bank is an original study resource designed for WGU E010 Foundations of Programming (Python) students preparing for the Objective Assessment. It covers all core competency domains: Python syntax and basic operations, data types and variables, control structures, functions and scope, data structures, string manipulation, file I/O, exception handling, and comprehensive code analysis. Questions are numbered sequentially from 1 to 1,000+ across the entire document. Each question includes four answer choices, the correct answer, and a concise rationale. Course Competencies Covered:
Q1. What is the correct way to output the string "Hello, World!" in Python? A. printf("Hello, World!") B. console.log("Hello, World!") C. print("Hello, World!") D. echo "Hello, World!" Answer: C Explanation: Python's built-in print() function outputs text to the console. The other options are used in other languages (C, JavaScript, PHP). Q2. Which symbol is used to begin a single-line comment in Python?
A. _my_var B. myVar C. my_var D. my var Answer: D Explanation: Variable names cannot contain spaces. Options A, B, and C are all valid variable names. Q6. What is the output of print(type(10))? A. B. C. 'int' D. Answer: A Explanation: The type() function returns the type object; printing it displays for an integer. Q7. Which of the following is a reserved keyword in Python? A. variable B. function C. if D. value Answer: C Explanation: if is a reserved keyword in Python used for conditional statements. The other options are not reserved keywords. Q8. What is the purpose of the input() function in Python?
A. To display output to the user B. To read input from the user as a string C. To convert a string to an integer D. To open a file Answer: B Explanation: The input() function reads a line from the user and returns it as a string. Q9. What data type does the input() function always return? A. int B. float C. str D. bool Answer: C Explanation: The input() function always returns a string. To use the input as a number, you must convert it using int() or float(). Q10. What is the output of print("Hello" + " " + "World")? A. Hello World B. HelloWorld C. Hello+World D. Error Answer: A Explanation: The + operator concatenates strings. With spaces included, the output is "Hello World". Q11. Which of the following correctly converts a string to an integer in Python? A. str(x) B. int(x)
Answer: C Explanation: The len() function returns the number of items in an object, such as a string, list, or tuple. Q15. What is the output of print(len("Hello"))? A. 4 B. 5 C. 6 D. Error Answer: B Explanation: len("Hello") returns 5 because the string "Hello" has five characters. Q16. What is the correct way to write a multi-line comment in Python? A. /* comment */ B. C. # comment D. Using triple quotes ("""comment""") Answer: D Explanation: While Python doesn't have a formal multi-line comment syntax, triple- quoted strings are often used for this purpose. Q17. What is the purpose of the print() function's sep parameter? A. To specify the separator between multiple arguments B. To specify the end character C. To format numbers D. To align text
Answer: A Explanation: The sep parameter specifies the separator between multiple arguments in the print() function. Q18. What is the purpose of the print() function's end parameter? A. To specify the separator between arguments B. To specify what to print at the end of the line C. To end the program D. To close the file Answer: B Explanation: The end parameter specifies what to print at the end of the line (default is a newline character \n). Q19. What is the output of print("Hello", "World")? A. HelloWorld B. Hello World C. Hello, World D. Hello+World Answer: B Explanation: The print() function separates multiple arguments with a space by default, producing "Hello World". Q20. What is the output of print("Hello", "World", sep="-")? A. Hello World B. Hello-World C. HelloWorld D. Hello, World
Answer: B Explanation: The / operator performs true division and always returns a float. 10 / 3 ≈ 3.333... Q24. What is the output of print(10 % 3)? A. 3 B. 1 C. 0 D. 3. Answer: B Explanation: The % operator returns the remainder. 10 % 3 = 1 (since 3 × 3 = 9, remainder 1). Q25. What is the output of print(2 ** 3)? A. 6 B. 8 C. 9 D. 5 Answer: B Explanation: The ** operator is the exponentiation operator. 2 ** 3 means 2 raised to the power of 3, which equals 8. Q26. What is the output of print(3 + 2 * 4)? A. 20 B. 14 C. 11 D. 24
Answer: C Explanation: Multiplication has higher precedence than addition. 2 * 4 = 8, then 3 + 8 =
Q27. What is the output of print((3 + 2) * 4)? A. 20 B. 14 C. 11 D. 24 Answer: A Explanation: Parentheses change the order of operations. 3 + 2 = 5, then 5 * 4 = 20. Q28. Which operator is used to check if two values are equal in Python? A. = B. == C. != D. === Answer: B Explanation: == is the equality comparison operator. = is the assignment operator. != means "not equal." === is not valid in Python. Q29. Which operator is used for assignment in Python? A. == B. = C. != D. <= Answer: B Explanation: The = operator assigns a value to a variable. == is used for comparison.
D. Error Answer: A Explanation: 5 is greater than or equal to 5, so the expression evaluates to True. Q34. Which of the following is the correct way to declare a variable in Python? A. int x = 5 B. x = 5 C. var x = 5 D. declare x = 5 Answer: B Explanation: Python uses dynamic typing — you simply assign a value to a variable name without declaring its type. Q35. What is the output of print(type(3.14))? A. B. C. D. Answer: B Explanation: Numbers with a decimal point are of type float (floating-point). Q36. What is the output of print(type(True))? A. B. C. D.
Answer: D Explanation: True and False are Boolean values of type bool. Q37. What is the output of print(type("Hello"))? A. B. C. D. Answer: C Explanation: Text enclosed in quotes is of type str (string). Q38. Which of the following is an immutable data type in Python? A. list B. dict C. set D. tuple Answer: D Explanation: A tuple cannot be changed after creation (immutable). Lists, dictionaries, and sets are mutable and can be modified after creation. Q39. Which of the following is a mutable data type in Python? A. tuple B. str C. list D. int Answer: C Explanation: Lists are mutable — their elements can be changed, added, or removed after creation.
A. True B. False C. 0. D. Error Answer: B Explanation: Due to floating-point precision issues, 0.1 + 0.2 does not exactly equal 0.3. This is a common pitfall in programming. Q44. What is the output of print(int(3.99))? A. 4 B. 3 C. 3. D. Error Answer: B Explanation: The int() function truncates the decimal part, so int(3.99) returns 3. Q45. What is the output of print(float(5))? A. 5 B. 5. C. 5. D. Error Answer: B Explanation: The float() function converts an integer to a floating-point number, so float(5) returns 5.0. Q46. What is the output of print(str(42))? A. 42 B. "42"
D. Error Answer: B Explanation: The str() function converts a value to a string. When printed, strings appear without quotes, so the output is 42. Q47. Which function returns the absolute value of a number? A. abs() B. absolute() C. fabs() D. positive() Answer: A Explanation: The abs() function returns the absolute value of a number. Q48. What is the output of print(abs(-5))? A. - 5 B. 5 C. 0 D. Error Answer: B Explanation: abs(-5) returns 5, the absolute value of - 5. Q49. Which function returns the largest of two or more numbers? A. max() B. largest() C. high() D. top()
Answer: B Explanation: Python uses banker's rounding, but round(3.5) returns 4 because 3. rounds to the nearest even number, which is 4. Q53. What is the output of print(divmod(10, 3))? A. (3, 1) B. (1, 3) C. (3.33, 0) D. (3, 0.33) Answer: A Explanation: divmod(10, 3) returns a tuple containing the quotient and remainder: ( // 3, 10 % 3) = (3, 1). Q54. What is the output of print(pow(2, 3))? A. 6 B. 8 C. 9 D. 5 Answer: B Explanation: pow(2, 3) returns 2 raised to the power of 3, which is 8. Q55. Which of the following is the correct way to swap two variables in Python? A. temp = a; a = b; b = temp B. a, b = b, a C. swap(a, b) D. a = b; b = a
Answer: B Explanation: Python allows multiple assignment, so a, b = b, a swaps the values of a and b in one line. Q56. What is the output of print("Hello" [0])? A. H B. e C. o D. Error Answer: A Explanation: String indexing starts at 0. "Hello"[0] returns the first character, 'H'. Q57. What is the output of print("Hello" [-1])? A. H B. e C. o D. Error Answer: C Explanation: Negative indexing starts from the end. "Hello"[-1] returns the last character, 'o'. Q58. What is the output of print("Hello" [1:4])? A. Hel B. ell C. llo D. Hell Answer: B Explanation: Slicing [1:4] includes characters at indices 1, 2, and 3: 'e', 'l', 'l' → "ell".