Docsity

WGU E010 OBJECTIVE ASSESSMENT 2 Foundations of Programming (Python) Complete WGU E010 O, Exams of Nursing

Toggle sidebar
bg1
WGU E010 OBJECTIVE ASSESSMENT 2 Foundations of Programming (Python)
Complete
WGU E010 Objective Assessment 2 - Foundations of Programming (Python)
SECTION 1: PYTHON FUNDAMENTALS & SYNTAX (Questions 1-30)
Question 1
What is the correct output of print("Hello, World!")?
A) "Hello, World!" (with quotes)
B) Hello, World! (without quotes)
C) print("Hello, World!")
D) An error occurs
Answer: B
Rationale: The print() function outputs the string literal to the console without the quotation
marks. The quotes are used only to denote the string in the code, not as part of the output .
Question 2
Which of the following is a valid variable name in Python?
A) 2nd_place
B) my-var
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 OBJECTIVE ASSESSMENT 2 Foundations of Programming (Python) Complete WGU E010 O and more Exams Nursing in PDF only on Docsity!

WGU E010 OBJECTIVE ASSESSMENT 2 Foundations of Programming (Python) Complete WGU E010 Objective Assessment 2 - Foundations of Programming (Python) SECTION 1: PYTHON FUNDAMENTALS & SYNTAX (Questions 1-30) Question 1 What is the correct output of print("Hello, World!")? A) "Hello, World!" (with quotes) B) Hello, World! (without quotes) C) print("Hello, World!") D) An error occurs Answer: B Rationale: The print() function outputs the string literal to the console without the quotation marks. The quotes are used only to denote the string in the code, not as part of the output. Question 2 Which of the following is a valid variable name in Python? A) 2nd_place B) my-var

C) my_var D) class Answer: C Rationale: Variable names must start with a letter or underscore, cannot contain hyphens, and cannot be reserved keywords like class. Question 3 What is the data type of the value 3.14 in Python? A) int B) float C) string D) boolean Answer: B Rationale: Numbers with a decimal point are of type float (floating-point). Integers have no decimal point. Question 4 What is the output of print(type(10 / 2))?

Question 6 What is the output of bool(0) in Python? A) True B) False C) None D) Error Answer: B Rationale: In Python, 0 is considered False when converted to a Boolean. Any non-zero number (positive or negative) is considered True in a Boolean context. Question 7 What is the result of bool([]) (empty list)? A) True B) False C) [] D) Error Answer: B

Rationale: Empty containers (list, dict, set, tuple, string) evaluate to False in a Boolean context. Non-empty containers are True. Question 8 Given x = 5 and y = 2, what is the result of x // y? A) 2. B) 2 C) 2. D) 1 Answer: B Rationale: The floor division operator // returns the integer quotient (discards remainder). 5 // 2 =

Question 9 Which operator is used to check if two values are equal in Python? A) = B) == C) !=

A) int("123") B) integer("123") C) str(123) D) float("123") Answer: A Rationale: int() converts a string (or float) to an integer. str() converts to a string, float() to a floating-point number. Question 12 What is the result of int("3.14")? A) 3 B) 3. C) Error D) 4 Answer: C Rationale: int() cannot directly convert a string containing a decimal point to an integer. It will raise a ValueError. To convert, first use float("3.14") then int().

Question 13 What is the data type of the value "42" in Python? A) int B) float C) str D) bool Answer: C Rationale: Values enclosed in quotation marks (single or double) are strings (str) in Python, even if they contain numeric characters. Question 14 Which of the following is a valid Boolean value in Python? A) "True" B) true C) True D) 1 Answer: C

Answer: A Rationale: The % operator is the modulo operator; it returns the remainder of division. 10 ÷ 3 = 3 with a remainder of 1. Question 17 What is the correct way to assign the value 25 to a variable named age in Python? A) age == 25 B) age := 25 C) age = 25 D) int age = 25 Answer: C Rationale: Python uses the assignment operator = to assign values to variables. == is the equality comparison operator, := is the walrus operator used in specific contexts, and int age = 25 is Java/C++ syntax. Question 18 In Python, which symbol begins a single-line comment? A) //

B)

C) /*

D)

Answer: B Rationale: String indexing in Python starts at 0. Index 0 is 'H', index 1 is 'e'. The code prints the character at index 1. Question 22 What is the output of the following code? python x = 5 y = 10 print(x + y) A) 510 B) 15 C) Error D) 5 10 Answer: B Rationale: The + operator performs arithmetic addition when both operands are integers (or numeric types). The values 5 and 10 are added together to produce the sum of 15.

Question 23 What is the output of the following code? python x = "5" y = 2 print(x * y) A) 10 B) Error C) "55" D) 7 Answer: C Rationale: When a string is multiplied by an integer, Python repeats (concatenates) the string that many times. The string "5" is repeated 2 times, resulting in "55". Question 24 What is the result of float("10.5")? A) 10 B) 10. C) Error

Answer: A Rationale: Python evaluates if/elif/else conditions in order and executes only the first block whose condition is True. Since x > 5 is True, 'A' is printed and the elif/else blocks are skipped entirely. Question 26 What must a developer do to run Python code written in a text editor? A) Save the file and use a Python interpreter B) Press a run button within the editor C) Upload the code to a web server D) Convert the code to machine language first Answer: A Rationale: Python is an interpreted language. To run code written in a text editor, you must save the file (with a .py extension) and execute it using a Python interpreter. Question 27 Which punctuation mark must appear at the end of an if statement line? A) Semicolon (;) B) Colon (:)

C) Period (.) D) Comma (,) Answer: B Rationale: In Python, an if statement line must end with a colon : to indicate that an indented block of code follows. Question 28 Which components are required in every Python for loop? A) A function call, a parameter, and a return value B) A list index, a range limit, and a step value C) A variable, an iterable, and an indented code block D) A condition, a counter, and a break statement Answer: C Rationale: A Python for loop needs a loop variable, an iterable object, and an indented code block that runs during each iteration. Question 29 What is the output of print(10 / 3)?

SECTION 2: DATA TYPES, TYPE CONVERSION, AND OPERATORS (Questions 31-60) Question 31 Which data type is immutable in Python? A) list B) dictionary C) tuple D) set Answer: C Rationale: Tuples are immutable, meaning their contents cannot be changed after creation. Lists, dictionaries, and sets are all mutable and can be modified after creation. Question 32 Given my_list = [1, 2, 3, 4], what does my_list[2] return? A) 1 B) 2 C) 3 D) 4

Answer: C Rationale: Python list indexing starts at 0. Index 2 gives the third element, which is 3. Question 33 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: C Rationale: Negative indexing starts from the end of the sequence. - 1 refers to the last element, which is 'cherry'. Question 34 Which data structure stores key-value pairs?