Docsity

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

Toggle sidebar
bg1
WGU E010 Foundations of Programming (Python) —
Complete Objective Assessment Test Bank
1,000+ OA-Style Multiple-Choice Questions with Answers &
Detailed Rationales (Updated Edition)
Exam Coverage: All 12 Chapters — Python Fundamentals · Variables & Data
Types · Operators & Expressions · Control Flow (Conditionals) · Loops &
Iteration · Functions & Scope · Data Structures (Lists, Tuples, Dictionaries, Sets) · String
Manipulation · File I/O & Exception Handling · Modules & Imports · Object-Oriented
Programming Basics · Debugging & Testing
Instructions: Each question is followed immediately by the correct answer and a
detailed rationale. Questions are numbered sequentially from 1 to 1,000+ across all
chapters.
Chapter 1: Python Fundamentals & Syntax (Questions 1–100)
Question 1: Which symbol begins a single-line comment in Python?
A) //
B) #
C) --
D) /*
Answer: B
Explanation: In Python, the hash symbol (#) begins a single-line comment. Everything
after # on that line is ignored by the interpreter. The // symbol is used for integer
division in Python, not comments.
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

Partial preview of the text

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

WGU E010 Foundations of Programming (Python) —

Complete Objective Assessment Test Bank

1,000+ OA-Style Multiple-Choice Questions with Answers &

Detailed Rationales (Updated Edition)

Exam Coverage: All 12 Chapters — Python Fundamentals · Variables & Data Types · Operators & Expressions · Control Flow (Conditionals) · Loops & Iteration · Functions & Scope · Data Structures (Lists, Tuples, Dictionaries, Sets) · String Manipulation · File I/O & Exception Handling · Modules & Imports · Object-Oriented Programming Basics · Debugging & Testing Instructions: Each question is followed immediately by the correct answer and a detailed rationale. Questions are numbered sequentially from 1 to 1,000+ across all chapters.

Chapter 1: Python Fundamentals & Syntax (Questions 1 – 100)

Question 1: Which symbol begins a single-line comment in Python? A) // B) # C) -- D) /* Answer: B Explanation: In Python, the hash symbol (#) begins a single-line comment. Everything after # on that line is ignored by the interpreter. The // symbol is used for integer division in Python, not comments.

Question 2: What is the correct file extension for a Python source file? A) .pt B) .pyt C) .py D) .python Answer: C Explanation: Python source files use the .py extension. For example, hello.py is a valid Python file name. Question 3: Which of the following is the correct way to output text to the console in Python? A) console.log("Hello") B) print("Hello") C) echo "Hello" D) printf("Hello") Answer: B Explanation: The print() function is Python's built-in function for displaying output to the console. console.log is JavaScript, echo is shell/PHP, and printf is C. Question 4: What is the purpose of indentation in Python?

A) Hello World B) HelloWorld C) Hello+World D) Error Answer: A Explanation: The + operator concatenates strings, including spaces. The output is Hello World. Question 7: Which function is used to get user input in Python 3? A) raw_input() B) input() C) scanf() D) read() Answer: B Explanation: In Python 3, input() reads a line from the user and returns it as a string. raw_input() was used in Python 2 and no longer exists. Question 8: What is the output of print(type(42))? A) B) C) D)

Answer: A Explanation: 42 is an integer literal, so type() returns . Question 9: Which keyword is used to define a function in Python? A) function B) def C) func D) define Answer: B Explanation: The def keyword begins a function definition in Python, e.g., def my_function():. Question 10: What is the output of print(10 // 3)? A) 3. B) 3 C) 4 D) 1 Answer: B Explanation: The // operator performs floor division, returning the integer quotient without the remainder. 10 // 3 = 3.

Answer: B Explanation: Python is an interpreted language, meaning code is executed line by line by the Python interpreter. Semicolons are optional and rarely used. Question 14: What does the following code do? python name = input("Enter your name: ") print("Hello, " + name) A) Prints "Hello, name" B) Asks for input and prints a personalized greeting C) Causes an error D) Prints only "Hello," Answer: B Explanation: input() prompts the user, stores their response in the variable name, then print() concatenates "Hello, " with the user's input. Question 15: Which of the following is the correct way to write a multi-line string? A) "This is a string" B) 'This is a string' C) """This is a multi-line string""" D) This is a string Answer: C

Explanation: Triple quotes (""" or ''') allow strings to span multiple lines in Python. Question 16: What is the output of print(2 ** 3)? A) 6 B) 8 C) 9 D) 5 Answer: B Explanation: The ** operator raises a number to a power. 2 raised to the power of 3 equals 8. Question 17: Which of the following data types is immutable in Python? A) list B) dict C) set D) tuple Answer: D Explanation: Tuples are immutable, meaning their contents cannot be changed after creation. Lists, dictionaries, and sets are mutable.

Question 20: What is the output of print(bool(0))? A) True B) False C) 0 D) Error Answer: B Explanation: In Python, 0 evaluates to False when converted to a boolean. Most other numbers evaluate to True. Question 21: Which method is used to convert a string to all uppercase? A) toUpper() B) uppercase() C) upper() D) toUpperCase() Answer: C Explanation: The .upper() method returns a copy of the string converted to uppercase, e.g., "hello".upper() returns "HELLO". Question 22: What will the following code print? python print(len("Python"))

A) 5

B) 6

C) 7

D) Error Answer: B Explanation: The len() function returns the number of characters in a string. "Python" has 6 characters. Question 23: Which of the following is a valid way to create a constant in Python? A) const PI = 3. B) PI = 3.14 (by convention, all caps) C) final PI = 3. D) constant PI = 3. Answer: B Explanation: Python does not have true constants. By convention, variables written in ALL_CAPS are treated as constants by programmers. Question 24: What is the output of print("abc" * 3)? A) abcabcabc B) abc C) abc abc abc D) Error

Explanation: int(x) converts the string "10" to the integer 10. Adding 5 gives 15. Question 27: Which of the following is used to define a block of code that runs only when a condition is true? A) for B) while C) if D) def Answer: C Explanation: The if statement executes a block of code only when its condition evaluates to True. Question 28: What does the following code do? python for i in range( 3 ): print(i) A) Prints 1, 2, 3 B) Prints 0, 1, 2 C) Prints 0, 1, 2, 3 D) Prints 3 three times Answer: B Explanation: range(3) generates the sequence 0, 1, 2. The loop prints each value.

Question 29: 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 equal in value, so the == comparison returns True. Question 30: Which of the following is a valid Boolean value in Python? A) true B) TRUE C) True D) yes Answer: C Explanation: Python Boolean values are True and False, with capital first letters. Question 31: What is the output of the following code? python a = 10 b = 3 print(a / b)

Answer: B Explanation: Slicing [1:4] returns characters at indices 1, 2, and 3, which are "e", "l", "l" — "ell". Question 34: Which keyword is used to exit a loop prematurely? A) exit B) stop C) break D) return Answer: C Explanation: The break statement immediately terminates the innermost loop and transfers control to the statement after the loop. Question 35: What does the following code output? python print("5" + "5") A) 10 B) 55 C) Error D) 5 Answer: B Explanation: Both operands are strings, so + concatenates them: "5" + "5" = "55".

Question 36: Which of the following is used to import a module in Python? A) include B) import C) require D) using Answer: B Explanation: The import statement is used to bring modules into the current namespace, e.g., import math. Question 37: What is the output of print(round(3.7))? A) 3 B) 4 C) 3. D) 3. Answer: B Explanation: round() rounds to the nearest integer. 3.7 rounds to 4. Question 38: Which of the following correctly checks if a value is of type int? A) if type(x) == int: B) if x is int:

Answer: C Explanation: Docstrings are triple-quoted strings placed at the beginning of a module, function, class, or method to document it. Question 41: What is the output of print(10 > 5 and 3 < 1)? A) True B) False C) Error D) None Answer: B Explanation: 10 > 5 is True, but 3 < 1 is False. The and operator returns True only if both operands are True. Question 42: Which of the following is the correct syntax for a while loop? A) while (condition) { } B) while condition: C) while condition do D) while condition: Answer: D Explanation: Python while loops use the syntax while condition: followed by an indented block. Parentheses are optional.

Question 43: What is the output of the following code? python fruits = ["apple", "banana", "cherry"] print(fruits[ 1 ]) A) apple B) banana C) cherry D) Error Answer: B Explanation: List indexing starts at 0. fruits[1] returns the second element, "banana". Question 44: Which of the following methods adds an item to the end of a list? A) add() B) append() C) insert() D) push() Answer: B Explanation: The append() method adds a single item to the end of a list. Question 45: What is the output of print("hello".capitalize())?