

























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
Ace the WGU E010 Foundations of Programming (Python) OA midterm Exam with practice questions covering variables, data types, input/output, arithmetic operators, strings, lists, dictionaries, conditionals, loops, functions, and basic debugging. This study guide helps reinforce foundational coding concepts and supports effective preparation for objective assessments. Designed to improve problem-solving skills and boost confidence in Python programming. Suitable for computer science, IT, and programming students.
Typology: Exams
1 / 33
This page cannot be seen from the preview
Don't miss anything!


























Ace the WGU E010 Foundations of Programming (Python) OA midterm Exam with practice questions covering variables, data types, input/output, arithmetic operators, strings, lists, dictionaries, conditionals, loops, functions, and basic debugging. This study guide helps reinforce foundational coding concepts and supports effective preparation for objective assessments. Designed to improve problem-solving skills and boost confidence in Python programming. Suitable for computer science, IT, and programming students. Multiple choice. Section 1: Variables, Data Types & Type Conversion
1. Which of the following is a valid variable name in Python? A) 2ndVariable B) my-var C) _myVar D) my var
Answer: C. _myVar Explanation: Variable names cannot start with a digit (A), cannot contain hyphens (B) or spaces (D). Underscore is allowed, including at the beginning.
2. What is the data type of 3.14? A) int B) float C) str D) bool Answer: B. float Explanation: Numeric values with a decimal point are of type float. Integers are whole numbers without a decimal point. 3. What is the output of print(type(5 / 2))? A) B) C) D) Answer: B. Explanation: In Python, the / operator always returns a floating-point result, even when the division is exact. 4. Which of the following will convert the string "123" to an integer? A) int("123") B) str("123")
Answer: B. 13 Explanation: Multiplication has higher precedence than addition. First 5 * 2 = 10, then 3 + 10 = 13.
7. What does the % operator do in Python? A) Percent B) Modulus – returns the remainder of division C) Division D) Exponentiation Answer: B. Modulus – returns the remainder of division Explanation: The modulus operator % gives the remainder after integer division. Example: 10 % 3 returns 1. 8. Which operator is used for floor division? A) / B) // C) % D) ** Answer: B. // Explanation: Floor division (//) divides and rounds down to the nearest integer. 10 // 3 equals 3. 9. What is the output of print(5 ** 2)? A) 10 B) 7 C) 25 D) 32
Answer: C. 25 Explanation: ** is the exponentiation operator. 5 raised to the power of 2 equals 25.
10. Which comparison operator means “not equal to”? A) = B) == C) != D) <> Answer: C. != Explanation: != is the not-equal operator in Python. It returns True if the two values are different. **Section 3: Strings & String Methods
C) Python D) pYTHON Answer: B. PYTHON Explanation: .upper() returns a new string where all letters are uppercase. Section 4: Lists & List Operations
16. Which of the following creates a list containing the numbers 1, 2, and 3? A) list(1, 2, 3) B) [1, 2, 3] C) {1, 2, 3} D) (1, 2, 3) Answer: B. [1, 2, 3] Explanation: Lists are written with square brackets []. Tuples use parentheses (), sets use {}. 17. What does append() do to a list? A) Adds an element to the beginning B) Adds an element to the end C) Removes the last element D) Removes the first element Answer: B. Adds an element to the end Explanation: append() adds a single element to the end of the list. To add at a specific position, use insert().
18. What is the output of the following code? python x = [1, 2, 3] y = x y.append(4) print(x) A) [1, 2, 3] B) [1, 2, 3, 4] C) [4] D) Error Answer: B. [1, 2, 3, 4] Explanation: y = x makes y a reference to the same list object as x. Modifying the list through y changes the same list that x refers to. 19. How do you access the last element of a list named data? A) data[0] B) data[-1] C) data[last] D) data[len(data)] Answer: B. data[-1] Explanation: Negative indices count from the end. - 1 always gives the last element.
C) person{"name"} D) person['name'] (also valid) Answer: B. person["name"] Explanation: Square brackets with the key name are used to access dictionary values. Both single and double quotes work.
23. Which method returns all the keys in a dictionary? A) keys() B) values() C) items() D) get() Answer: A. keys() Explanation: dict.keys() returns a view object containing all keys. values() returns values, items() returns key-value pairs. **Section 6: Conditionals (if/elif/else)
else: print("C") A) A B) B C) C D) Error Answer: B. B Explanation: x > 10 is False, so it moves to the elif. x > 0 is True, so it prints "B".
25. Which logical operator returns True only when both conditions are true? A) or B) not C) and D) xor Answer: C. and Explanation: The and operator requires both operands to be True to return True. 26. What is the output of print(True and False)? A) True B) False C) 1 D) 0
D) Infinite Answer: B. 5 Explanation: The loop runs while i < 5. Values of i are 0,1,2,3,4 – five times. Then i becomes 5 and the condition fails.
29. What is the output of the following code? python for i in range(3): print(i, end=" ") A) 0 1 2 B) 1 2 3 C) 0 1 2 3 D) 1 2 3 4 Answer: A. 0 1 2 Explanation: range(3) generates numbers starting at 0 up to, but not including, 3. 30. Which keyword is used to exit a loop prematurely? A) exit B) stop C) break D) continue Answer: C. break Explanation: break immediately terminates the innermost
loop. continue skips the rest of the current iteration and goes to the next.
31. What is the output of the following code? python for i in range(1, 5): if i == 3: continue print(i, end=" ") A) 1 2 3 4 B) 1 2 4 C) 1 2 3 D) 2 3 4 Answer: B. 1 2 4 Explanation: When i equals 3, continue skips the print statement, so 3 is not printed. **Section 8: Functions
Explanation: return ends the function and can pass a value back. Without a return, the function returns None.
35. Which of the following is a correct function call for def greet(name="Guest")? A) greet() B) greet("Alice") C) Both A and B are valid D) Neither is valid Answer: C. Both A and B are valid Explanation: The parameter name has a default value "Guest". The function can be called with no argument (uses default) or with an argument. **Section 9: Input & Output
37. What is the output of print("Hello", "World", sep="-")? A) Hello-World B) Hello World C) Hello-World (no quotes) D) Hello,World Answer: A. Hello-World Explanation: The sep parameter defines the separator between multiple printed items. The default separator is a space. Here it is changed to a hyphen. 38. What is the output of print("Hello", end="") followed by print("World")? A) Hello World B) HelloWorld C) Hello World D) Error Answer: B. HelloWorld Explanation: By default, print() ends with a newline (end="\n"). Setting end="" suppresses the newline, so "Hello" and "World" print on the same line. **Section 10: Errors & Debugging
41. Which of the following statements about Python is true? A) Python uses semicolons to end statements. B) Python uses indentation to define code blocks. C) Python does not support object-oriented programming. D) Python is a compiled language only. Answer: B. Python uses indentation to define code blocks. Explanation: Python relies on consistent indentation (usually 4 spaces) to group statements; braces are not used. 42. What is the result of print(10 // 3)? A) 3 B) 3.333… C) 4 D) 3. Answer: A. 3 Explanation: Floor division (//) returns the integer part of the quotient, discarding the remainder. 43. What does the range(2, 8, 2) function generate? A) 2, 4, 6, 8 B) 2, 4, 6 C) 2, 3, 4, 5, 6, 7 D) 2, 4, 6, 8, 10 Answer: B. 2, 4, 6 Explanation: Start = 2, stop = 8 (excluded), step = 2. So numbers are 2, 4, 6.
44. Which of the following is used to create an empty list? A) list() B) [] C) Both A and B D) None Answer: C. Both A and B Explanation: [] is the literal syntax; list() is the constructor. Both produce an empty list. 45. Which method removes an item from a list by its value? A) pop() B) remove() C) delete() D) del Answer: B. remove() Explanation: remove(x) deletes the first occurrence of value x. pop() removes by index. 46. What is the output of print(3 ** 2 ** 3)? A) 512 B) 729 C) 19683 D) 27 Answer: A. 512 Explanation: Exponentiation operators are evaluated from right to left. 2 ** 3 = 8, then 3 ** 8 = 6561. Wait: careful: 3 ** (2 ** 3) = 3 ** 8 = 6561. But typical exponentiation precedence: