
































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!

































Course: WGU E010 – Foundations of Programming (Python) Format: Multiple Choice with Answer Key and Rationale Coverage: All Course Chapters Total Questions: 1, ================================================================================ ================================================================================ TABLE OF CONTENTS ================================================================================ Part 1: Programming Fundamentals & Python Basics (Questions 1–100) Part 2: Variables, Data Types & Type Conversion (Questions 101–200) Part 3: Operators & Expressions (Questions 201–300) Part 4: Conditional Statements (if/elif/else) (Questions 301–400) Part 5: Loops (while, for, range, break, continue) (Questions 401–520) Part 6: Functions, Parameters & Scope (Questions 521–640) Part 7: Strings & String Methods (Questions 641–740) Part 8: Lists, Tuples & Sets (Questions 741–840) Part 9: Dictionaries (Questions 841–920) Part 10: File I/O & Exception Handling (Questions 921–980) Part 11: Object-Oriented Programming (Questions 981–1020) ================================================================================ PART 1: PROGRAMMING FUNDAMENTALS & PYTHON BASICS (Questions 1–100) ================================================================================ Question 1. What is a program?
A. A physical component of a computer B. A set of instructions that a computer executes C. A type of memory D. A programming language Answer: B Explanation: A program is a sequence of instructions executed by the computer. Question 2. What is an algorithm? A. A step-by-step procedure for solving a problem B. A programming language C. A loop D. A syntax error Answer: A Explanation: An algorithm is a finite ordered set of steps that solves a problem. Question 3. Which is NOT a programming language? A. Python B. Java C. C++ D. Microsoft Word Answer: D Explanation: Microsoft Word is an application, not a programming language. Question 4. What does "syntax" mean in programming? A. Meaning of a statement B. Rules defining valid code structure C. Speed of a program D. Color of code Answer: B
C. Assembly language D. Markup language Answer: B Explanation: Python is interpreted and dynamically typed. Question 9. Which file extension is used for Python source files? A. .java B. .py C. .exe D. .html Answer: B Explanation: Python source files use .py. Question 10. What is the output of print("Hello, World!")? A. Hello, World! B. "Hello, World!" C. print(Hello, World!) D. Error Answer: A Explanation: print() displays the string without quotes. Question 11. Which function displays output in Python? A. input() B. output() C. print() D. display() Answer: C Explanation: print() writes to standard output.
Question 12. Which function reads user input? A. print() B. input() C. read() D. scan() Answer: B Explanation: input() reads a line from the user. Question 13. What type does input() return? A. int B. float C. str D. bool Answer: C Explanation: input() always returns a string. Question 14. Which symbol begins a single-line comment? A. // B. # C. -- D. /* */ Answer: B Explanation: Python uses # for single-line comments. Question 15. How do you write a multi-line comment or docstring? A. # on every line B. Triple quotes """ """ C. // at start D.
B. No, Python is case-sensitive C. Only in Python 2 D. Only inside functions Answer: B Explanation: Python identifiers are case-sensitive. Question 20. Which of these is a reserved keyword? A. main B. total C. while D. value Answer: C Explanation: while is a Python keyword. Question 21. What does x = 5 do? A. Compares x to 5 B. Binds x to integer 5 C. Defines a function D. Imports a module Answer: B Explanation: = is the assignment operator. Question 22. In x = 10, what is "="? A. Equality operator B. Assignment operator C. Comparison operator D. Logical operator Answer: B Explanation: "=" assigns; "==" tests equality.
Question 23. Which statement assigns 5 to both a and b? A. a = b = 5 B. a == b == 5 C. a := b := 5 D. a = 5, b = 5 Answer: A Explanation: Chained assignment a = b = 5 sets both. Question 24. What does x += 3 do? A. Compares x to 3 B. Adds 3 to x and assigns back to x C. Sets x to 3 D. Deletes x Answer: B Explanation: += is augmented assignment. Question 25. Which operator tests equality? A. = B. == C. === D. != Answer: B Explanation: == compares equality. Question 26. What does != mean? A. Assign not equal B. Not equal to C. Equal to
Answer: B Explanation: / is true division, returns a float. Question 31. Which is an int literal? A. 3. B. "42" C. 42 D. 4.2e Answer: C Explanation: 42 is an int. Question 32. Which is a float literal? A. 7 B. 7. C. "7" D. 0b Answer: B Explanation: 7.0 has a decimal point. Question 33. Which is a Boolean value? A. 0 B. True C. "true" D. 1. Answer: B
Explanation: True and False are Boolean literals. Question 34. What is bool(0)? A. True B. False C. 0 D. Error Answer: B Explanation: Zero is falsy. Question 35. What is bool("hello")? A. True B. False C. Error D. None Answer: A Explanation: Non-empty strings are truthy. Question 36. What is bool("")? A. True B. False C. Error D. None Answer: B Explanation: Empty string is falsy. Question 37. What is int("25")? A. "25" B. 25
Question 41. What does print(type(5.0)) output? A. B. C. D. Answer: B Explanation: 5.0 is float. Question 42. What does print(type("5")) output? A. B. C. D. Answer: C Explanation: Quoted values are strings. Question 43. What does print(type(True)) output? A. B. C. D. Answer: D Explanation: True is a Boolean. Question 44. How do you convert input to an integer? A. str(input()) B. int(input()) C. float(str()) D. bool(input())
Answer: B Explanation: int(input()) parses the string as an integer. Question 45. What happens if int("abc") is executed? A. Returns 0 B. Returns None C. Raises ValueError D. Returns "abc" Answer: C Explanation: Non-numeric strings raise ValueError. Question 46. What is int(3.9)? A. 4 B. 3 C. 3. D. Error Answer: B Explanation: int() truncates toward zero. Question 47. What is round(3.5)? A. 3 B. 4 C. 3. D. Error Answer: B Explanation: Python uses banker's rounding; 3.5 → 4. Question 48. What is round(2.5)? A. 2
Question 52. What is pow(2, 4)? A. 8 B. 16 C. 6 D. 24 Answer: B Explanation: pow(2,4) = 2^4 = 16. Question 53. Which statement about Python is TRUE? A. Indentation is optional B. Indentation defines blocks C. Semicolons are required at line ends D. Braces define blocks Answer: B Explanation: Python uses indentation to define blocks. Question 54. What is the conventional indentation width? A. 1 space B. 2 spaces C. 4 spaces D. 8 spaces Answer: C Explanation: PEP 8 recommends 4 spaces. Question 55. What is a code block? A. A group of statements executed together B. A single statement C. A comment
D. A variable Answer: A Explanation: A block is a set of statements grouped by indentation. Question 56. What is a traceback? A. Error report showing the call stack B. A loop C. A variable D. A function Answer: A Explanation: Tracebacks show where errors occurred. Question 57. What is the purpose of the Python interpreter? A. To compile machine code B. To execute Python code C. To design web pages D. To manage files Answer: B Explanation: The interpreter executes Python source. Question 58. Which command runs a Python script? A. python script.py B. run script.py C. execute script.py D. compile script.py Answer: A Explanation: python runs the script. Question 59. What is the Python shell used for?
Explanation: type() returns the class of the argument. Question 63. What does the pass statement do? A. Exits the program B. Does nothing; a placeholder C. Raises an error D. Restarts the loop Answer: B Explanation: pass is a null statement. Question 64. What does break do? A. Skips the current iteration B. Exits the loop immediately C. Restarts the loop D. Raises an error Answer: B Explanation: break terminates the enclosing loop. Question 65. What does continue do? A. Exits the loop B. Skips to the next iteration C. Restarts the loop D. Raises an error Answer: B Explanation: continue skips the rest of the current iteration. Question 66. Which is a valid Python statement? A. x = 5 B. x == 5
C. 5 = x D. x := 5 Answer: A Explanation: Only x = 5 is valid assignment (:= requires a context). Question 67. What is 5 + 3 * 2? A. 16 B. 11 C. 13 D. 10 Answer: B Explanation: Multiplication first: 32=6, 5+6=11. Question 68. What is (5 + 3) * 2? A. 16 B. 11 C. 13 D. 10 Answer: A Explanation: Parentheses: 82=16. Question 69. What is 10 - 4 - 3? A. 9 B. 3 C. 4 D. - 1 Answer: B Explanation: Left-to-right: 10-4=6, 6-3=3.