




























































































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 E 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: Identifies Python Programming Constructs (30%) Executes Python Code (17%)
Manipulates Data Structures (23%) Creates Functional Programs (30%) Core Topic Domains:
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: Variable names must start with a letter or underscore, cannot contain hyphens, and cannot be a reserved keyword (class is a keyword). Underscores are allowed and commonly used. Q5. Which of the following is NOT a valid variable name 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: B Explanation: Python scripts are saved with the .py file extension. Q14. Which function is used to determine the length of a string or collection? A. size() B. length() C. len() D. count() 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 // operator performs floor division, returning the integer quotient (discards the remainder). 10 // 3 = 3. Q23. What is the output of print(10 / 3)? A. 3 B. 3. C. 3. D. 4 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 = 11. 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
Q32. What is the output of print(5 < 3)? A. True B. False C. 5 D. Error Answer: B Explanation: 5 is not less than 3, so the expression evaluates to False. Q33. What is the output of print(5 >= 5)? A. True B. False C. 5 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
D. Error Answer: A Explanation: bool(1) returns True. Non-zero numbers, non-empty strings, and non-empty collections are considered True. Q42. Which of the following values represents a Boolean false value in Python? A. "False" B. 0 C. FALSE D. False Answer: D Explanation: The keyword False (with capital F) represents the Boolean false value in Python. Q43. What is the output of print(0.1 + 0.2 == 0.3)? 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
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" C. '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()
Answer: A Explanation: The min() function returns the smallest item in an iterable or the smallest of two or more arguments. Q51. What is the output of print(round(3.14159, 2))? A. 3. B. 3. C. 3. D. 3. Answer: A Explanation: The round() function rounds to the specified number of decimal places. round(3.14159, 2) returns 3.14. Q52. What is the output of print(round(3.5))? A. 3 B. 4 C. 3. D. Error Answer: B Explanation: Python uses banker's rounding, but round(3.5) returns 4 because 3.5 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: (10 // 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