




































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 practice Exam with practice questions covering Python syntax, data types, control structures, functions, data structures (lists, tuples, dictionaries, sets), file I/O, exception handling, modules, and basic object-oriented programming. 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 / 44
This page cannot be seen from the preview
Don't miss anything!





































Ace the WGU E010 Foundations of Programming (Python) OA practice Exam with practice questions covering Python syntax, data types, control structures, functions, data structures (lists, tuples, dictionaries, sets), file I/O, exception handling, modules, and basic object-oriented programming. 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: Python Fundamentals & Syntax (Questions 1–15)
1. What is the correct output of the following Python code? print("Hello, World!") A) Hello, World! B) Hello, World!
C) print("Hello, World!") D) An error occurs Answer: A. Hello, World! Explanation: The print() function outputs the string literal to the console without the quotation marks. The quotes are used only to denote the string.
2. Which of the following is a valid variable name in Python? A) 2_variable B) my-variable C) _myVariable D) my variable Answer: C. _myVariable **Explanation: Variable names can start with a letter or underscore, cannot start with a digit, and cannot contain spaces or hyphens. Underscore is allowed.
7. Which operator is used for exponentiation (power) in Python? A) ^ B) ** C) * D) // Answer: B. ** Explanation: ** is the exponentiation operator (e.g., 2 ** 3 equals 8). The ^ **operator is used for bitwise XOR.
Answer: B. 1 Explanation: % is the modulo operator; it returns the remainder of division (10 divided by 3 gives remainder 1).
10. Which of the following correctly converts the string "123" to an integer? A) int("123") B) integer("123") C) str(123) D) "123".to_int() Answer: A. int("123") Explanation: The built-in int() **function converts a string (or other numeric type) to an integer, provided the string represents a valid integer.
15. What does bool(0) return? A) True B) False C) 0 D) None Answer: B. False Explanation: In Python, numeric values: 0, 0.0, and complex zero evaluate to False in a Boolean context. All non-zero numbers evaluate to True**. Section 2: Control Flow (if, elif, else, loops) (Questions 16–30)
D) No output Answer: A. A Explanation: The first condition x > 5 is True (10 > 5), so the block under if executes and prints "A". The elif and else blocks are skipped.
17. Which logical operator would be used to check if both conditions a > 5 and b < 10 are True? A) or B) and C) not D) & Answer: B. and Explanation: The and operator returns True only when both operands are True**. This matches the requirement that both conditions must hold.
Answer: C. break Explanation: The break statement terminates the innermost loop (while or for) immediately and resumes execution after the loop.
21. What is the output of the following code? python for i in range(1, 6, 2): print(i, end=" ") A) 1 2 3 4 5 B) 1 3 5 C) 2 4 6 D) 1 3 5 7 Answer: B. 1 3 5 Explanation: range(1, 6, 2) **starts at 1, goes up to but not including 6, with a step of 2. So the values are 1, 3, and 5.
<= 20 is equivalent to n >= 10 and n <= 20. range(10,20) excludes 20, so it's not inclusive of 20.
23. What is the output of print(not (5 > 3) or (2 == 2))? A) False B) True C) None D) Error Answer: B. True Explanation: (5 > 3) is True, so not True is False. (2 == 2) is True. False or True **evaluates to True.
break print(i, end=" ") A) 0 B) 0 1 C) 0 1 2 D) No output Answer: A. 0 Explanation: When i = 0, condition false, print 0. When i = 1, i == 1 is True, break exits the loop immediately without printing 1 or further values.
28. How many times will "Hello" be printed? python i = 0 while i < 5: print("Hello") i += 2 A) 2 B) 3 C) 4 D) 5 Answer: B. 3 Explanation: i starts 0 → print, i=2; i=2 → print, i=4; i=4 → print, i=6; now i=6 not <5, stop. Three prints.
29. Which expression evaluates to True if age is NOT between 18 and 65 inclusive? A) age < 18 or age > 65 B) not (18 <= age <= 65) C) both A and B D) age not in range(18,66) Answer: C. both A and B Explanation: Both correctly represent the condition. range(18,66) includes 65, so age not in range(18,66) **also works but is less common for numeric comparisons.
python def add(a, b): return a + b result = add(3, 4) print(result) A) 7 B) 12 C) add(3,4) D) Error Answer: A. 7 Explanation: The function takes two parameters and returns their sum. add(3,4) returns 7, which is assigned to result and printed.
34. A variable defined inside a function is called a __________ variable. A) global B) local C) static D) constant **Answer: B. local Explanation: Variables declared inside a function have local scope; they are not accessible outside that function unless returned or passed.
python x = 10 def change(): x = 20 change() print(x) A) 10 B) 20 C) None D) Error Answer: A. 10 Explanation: Inside change() , x = 20 creates a local variable x that shadows the global x. The global x remains unchanged, so print(x) outputs 10.
36. How do you make a function return a value without using return? A) It's impossible; functions without return return None B) Use yield C) Use print() D) Use pass Answer: A. It's impossible; functions without return return None Explanation: If no return statement is executed, or a return with no value, the function returns None implicitly.
tuple. **kwargs collects keyword arguments into a dictionary.
39. What is the output? python def func(x, y=2, z=3): return x + y + z print(func(1, z=4)) A) 6 B) 7 C) 8 D) Error Answer: B. 7 Explanation: x=1 (positional), y uses default 2, z **is overridden to 4. Sum = 1+2+4 = 7.
41. What is the scope of a variable defined inside a function? A) Global B) Local to that function C) Enclosing function only if nested D) Both B and C **Answer: D. Both B and C Explanation: A variable defined inside a function is local to that function. If the function is nested inside another function, it is local to the inner function and can be accessed by the inner function (but not by the outer function).