Docsity

WGU E010 Foundations of Programming (Python) — Complete Objective Assessment Practice Bank, Exams of Nursing

Toggle sidebar
bg1
WGU E010 Foundations of Programming
(Python) — Complete Objective Assessment
Practice Bank: 1,000+ OA-Style Questions
with Verified Answers & Detailed Rationales |
Exam Edition | All Chapters Covered
TABLE OF CONTENTS
Section Topic Questions
1 Python Fundamentals, Syntax & Data Types 1–120
2 Variables, Type Conversion & Operators 121–220
3 Control Flow — Conditionals 221–320
4 Loops & Iteration 321–440
5 Functions, Scope & Modular Design 441–560
6 Data Structures — Lists & Tuples 561–680
7 Data Structures — Dictionaries & Sets 681–780
8 String Manipulation & Methods 781–880
9 File Handling & Exception Handling 881–960
10 Object-Oriented Programming & Debugging 961–1020
11 Comprehensive Review & Code Analysis 1021–1050
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download WGU E010 Foundations of Programming (Python) — Complete Objective Assessment Practice Bank and more Exams Nursing in PDF only on Docsity!

WGU E010 Foundations of Programming

(Python) — Complete Objective Assessment

Practice Bank: 1,000+ OA-Style Questions

with Verified Answers & Detailed Rationales |

Exam Edition | All Chapters Covered

TABLE OF CONTENTS

Section Topic Questions 1 Python Fundamentals, Syntax & Data Types 1– 2 Variables, Type Conversion & Operators 121– 3 Control Flow — Conditionals 221– 4 Loops & Iteration 321– 5 Functions, Scope & Modular Design 441– 6 Data Structures — Lists & Tuples 561– 7 Data Structures — Dictionaries & Sets 681– 8 String Manipulation & Methods 781– 9 File Handling & Exception Handling 881– 10 Object-Oriented Programming & Debugging 961– 11 Comprehensive Review & Code Analysis 1021–

SECTION 1: PYTHON FUNDAMENTALS,

SYNTAX & DATA TYPES (Questions 1–120)

Q1. Which symbol is used to begin a single-line comment in Python? A. // B. # C. /* */ D. -- Answer: B Explanation: Python uses the hash symbol (#) for single-line comments. Everything after # on that line is ignored by the interpreter. Q2. Which built-in function is used to display output to the console in Python? A. display() B. output() C. print() D. show() Answer: C Explanation: The print() function sends text or other values to standard output. The other options are not valid Python built-in functions.

Answer: C Explanation: Python's Boolean values are True and False (capitalized first letter). "True" is a string, true is not a valid keyword (Python is case- sensitive), and 1 is an integer. Q6. Which of the following is a valid variable name in Python? A. 2nd_place B. my-var C. my_var D. class 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. Q7. What is the output of print(type(10 / 2))? A. B. C. D. Answer: B Explanation: In Python, the / operator performs true division and always returns a float, even when the numbers divide evenly. 10 / 2 = 5.0, so type(5.0) is .

Q8. Which of the following data types is immutable 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. Q9. What is the output of print(5 > 3 and 2 < 1)? A. True B. False C. None D. Error Answer: B Explanation: 5 > 3 is True, but 2 < 1 is False. The and operator returns True only when both conditions are True, so the result is False. Q10. Which operator is used to check if two values are equal in Python? A. = B. ==

Q13. What is the output of print(len("Programming"))? A. 10 B. 11 C. 12 D. Error Answer: B Explanation: len() counts the number of characters in a string. "Programming" has 11 characters. Q14. What is the result of type conversion: int("10.5")? A. 10 B. 10. C. Error (ValueError) D. 11 Answer: C Explanation: int() cannot convert a string containing a decimal point directly to an integer. This raises a ValueError. To convert "10.5" to a number, first use float("10.5"), then int if needed. Q15. Which keyword is used to define a function in Python? A. function B. def

C. define D. func Answer: B Explanation: The def keyword begins a function definition in Python. function is not a Python keyword. Q16. 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. Q17. Which symbol begins a single-line comment in Python? A. // (double forward slash) B. # (pound symbol) C. * (asterisk) D. % (percent symbol) Answer: B Explanation: The hash symbol (#) begins a single-line comment. The interpreter ignores everything after # on that line.

C. A number D. A variable name Answer: B Explanation: In Python, the for loop iterates over an iterable object (such as a list, tuple, string, or range). The syntax is for item in iterable:. Q21. Which terminal command is used to navigate to a different directory before running a Python script? A. move B. goto C. cd D. nav Answer: C Explanation: The cd (change directory) command is used to navigate to a different directory in a terminal. Q22. What is the output of print(10 // 3)? A. 3. B. 3 C. 3. D. 4 Answer: B Explanation: The floor division operator // returns the integer quotient (discards the remainder). 10 // 3 = 3.

Q23. What is the output of print(10 % 3)? A. 3 B. 1 C. 3. D. 0 Answer: B Explanation: The modulo operator % returns the remainder of division. 10 % 3 = 1 (since 3 × 3 = 9, and 10 − 9 = 1). Q24. Which of the following is a valid Python identifier? A. 2nd_value B. my-value C. class D. _total_count Answer: D Explanation: Identifiers may start with a letter or underscore and may contain letters, digits, and underscores. They cannot start with a digit or be a reserved keyword such as class. Q25. What is the output of print("Hello" + "World")? A. Hello World B. HelloWorld

Q28. Which of the following is the correct way to assign a value to a variable in Python? A. int x = 5 B. x := 5 C. x = 5 D. var x = 5 Answer: C Explanation: Python uses the assignment operator = to assign values to variables. No type declaration is needed. Q29. What is the output of print(3 == 3.0)? A. True B. False C. Error D. None Answer: A Explanation: In Python, 3 and 3.0 are considered equal in value. The == operator compares values, not types. Q30. Which function returns the data type of an object in Python? A. datatype() B. type()

C. typeof() D. gettype() Answer: B Explanation: The type() function returns the data type of an object. For example, type(5) returns . Q31. What is the output of print(5 != 3)? A. True B. False C. Error D. None Answer: A Explanation: The != operator checks if two values are not equal. Since 5 is not equal to 3, the result is True. Q32. Which of the following is a valid way to declare a multi-line string in Python? A. "line1\nline2" B. 'line1' + 'line2' C. '''line line2''' D. (line1, line2) Answer: C Explanation: Triple quotes (''' or """) allow multi-line strings. Option A works

Q35. Which of the following statements about Python variables is TRUE? A. Variables must be declared with a type before use. B. Variables are dynamically typed. C. Variables cannot change type after assignment. D. Variable names are case-insensitive. Answer: B Explanation: Python is dynamically typed, meaning the type of a variable is determined at runtime and can change. No explicit declaration is required. Q36. What is the output of print(type(True))? A. B. C. D. Answer: B Explanation: True and False are Boolean values with type bool. type(True) returns . Q37. What is the output of print(int(3.99))? A. 4 B. 3 C. 3. D. Error

Answer: B Explanation: int() truncates the decimal portion when converting a float to an integer. int(3.99) returns 3, not 4. Q38. Which of the following is a valid float literal in Python? A. 3 B. 3. C. "3.0" D. 3e Answer: B Explanation: A float literal must contain a decimal point or use scientific notation. 3.0 is a valid float literal. Q39. What is the output of print("Python"[0])? A. P B. y C. n D. Error Answer: A Explanation: String indexing starts at 0. "Python"[0] returns the first character, 'P'.

Answer: B Explanation: 10 is an integer and "10" is a string. The == operator compares both value and type, so they are not equal. Q43. Which of the following is NOT a Python data type? A. int B. float C. double D. str Answer: C Explanation: Python does not have a double data type. Floating-point numbers are represented by the float type. Q44. What is the output of print(15 / 4)? A. 3 B. 3. C. 3. D. 4 Answer: B Explanation: The / operator performs true division and returns a float. 15 / 4 = 3.75.

Q45. What is the output of print(15 // 4)? A. 3 B. 3. C. 3. D. 4 Answer: A Explanation: The // operator performs floor division and returns the integer quotient. 15 // 4 = 3. Q46. Which of the following creates an empty list in Python? A. list() B. [] C. Both A and B D. {} Answer: C Explanation: Both list() and [] create an empty list. {} creates an empty dictionary, not a list. Q47. What is the output of print(2 + 3 * 4)? A. 20 B. 14 C. 24 D. 12