Docsity

WGU E010 Foundations of Programming (Python) Objective Assessment, Exams of Nursing

Toggle sidebar
bg1
WGU E010 Foundations of Programming (Python) Objective
Assessment
Section 1: Basic Syntax & Data Types (Questions 1–25)
**Q1. What is the correct way to create a variable named `age` with the value 25
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. No type declaration is needed. `==` is a comparison operator, `:=` is the
walrus operator used in expressions, and `int age = 25` is invalid Python syntax.
---
**Q2. What is the output of `print(type(10 / 2))`?**
- A) `<class 'int'>`
- B) `<class 'float'>`
- C) `<class 'double'>`
- D) `<class 'str'>`
**Answer: B**
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

Partial preview of the text

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

WGU E010 Foundations of Programming (Python) Objective Assessment Section 1: Basic Syntax & Data Types (Questions 1–25) Q1. What is the correct way to create a variable named age with the value 25 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. No type declaration is needed. == is a comparison operator, := is the walrus operator used in expressions, and int age = 25 is invalid Python syntax.

Q2. What is the output of print(type(10 / 2))?

  • A) ``
  • B) ``
  • C) ``
  • D) `` Answer: B

Rationale: 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 float.

Q3. Which of the following data types is immutable?

  • A) list
  • B) dict
  • C) set
  • D) tuple Answer: D Rationale: A tuple cannot be changed after creation (immutable), while lists, dicts, and sets are mutable and can be modified.

Q4. Which data type is the value 3.14 in Python?

  • A) Integer
  • B) Float
  • C) String
  • D) Boolean Answer: B

Rationale: The ** operator is the exponentiation operator. 2 ** 3 means 2 raised to the power of 3, which equals 8.

Q7. What is the output of print(3 + 2 * 4)?

  • A) 20
  • B) 14
  • C) 11
  • D) 24 Answer: C Rationale: Operator precedence: multiplication before addition. 2 * 4 = 8, then 3 + 8 = 11.

Q8. Which symbol begins a single-line comment in Python?

  • A) // (double forward slash)
  • B) # (pound symbol)
  • C) * (asterisk)
  • D) % (percent symbol) Answer: B

Rationale: In Python, the # symbol is used to begin a single-line comment. Everything after # on that line is ignored by the interpreter.

Q9. Which function is used to convert a string to an integer in Python?

  • A) str()
  • B) int()
  • C) float()
  • D) convert() Answer: B Rationale: The int() function converts a value to an integer. str() converts to a string, and float() converts to a floating-point number.

Q10. What is the result of int("3.14")?

  • A) 3
  • B) 3.14
  • C) Error
  • D) 4 Answer: C

Rationale: Empty sequences (list, tuple, string, dict, set) evaluate to False in a Boolean context. Non-empty containers are True.

Q13. Which operator checks equality in Python?

  • A) =
  • B) ==
  • C) !=
  • D) === Answer: B Rationale: == is the equality comparison operator. = is assignment. != means "not equal". === is not valid in Python.

Q14. What is the correct output of print("Hello, World!")?

  • A) Hello, World!
  • B) "Hello, World!"
  • C) Error
  • D) Hello World Answer: A

Rationale: The print() function outputs the string without the quotation marks.

Q15. Which of the following is a valid variable name in Python?

  • A) 2nd_place
  • B) my_var
  • C) my-var
  • D) class Answer: B Rationale: Variable names must start with a letter or underscore, cannot contain hyphens, and cannot be a reserved keyword (class is a keyword).

Q16. Which of the following is a valid Boolean value in Python?

  • A) "True"
  • B) true
  • C) True
  • D) 1 Answer: C
  • C) l
  • D) o Answer: B Rationale: String indexing starts at 0 in Python. x[0] = 'H', x[1] = 'e', so the output is 'e'.

Q19. 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).

Q20. Given x = 5 and y = 2, what is the result of x // y?

  • A) 2.5
  • B) 2
  • C) 2.0
  • D) 1

Answer: B Rationale: The floor division operator // returns the integer quotient (discards the remainder). 5 // 2 = 2.

Q21. What is the output of print(type(10))?

  • A) ``
  • B) int
  • C) 'int'
  • D) Error Answer: A Rationale: The type() function returns the type object; printing it displays ``.

Q22. Which of the following is NOT a valid way to create a string in Python?

  • A) "hello"
  • B) 'hello'
  • C) hello
  • D) """hello"""

Answer: B Rationale: Empty containers (list, dict, set, tuple, string) evaluate to False in a Boolean context. Non-empty containers are True.

Q25. 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. my_list[0] = 1, my_list[1] = 2, my_list[2] = 3.

Section 2: Control Flow & Loops (Questions 26–50)

Q26. In Python, what must follow the in keyword in a for loop?

  • A) A condition
  • B) An iterable object
  • C) A number
  • D) A variable name

Answer: B Rationale: In a for loop, the in keyword must be followed by an iterable object (e.g., list, tuple, string, range).

Q27. Which type of loop is designed for iterating a specific number of times?

  • A) while loop
  • B) for loop
  • C) infinite loop
  • D) do-while loop Answer: B Rationale: A for loop is designed to iterate a specific number of times (e.g., over a range or sequence). A while loop runs until a condition becomes false.

Q28. Which type of loop is best used when the number of iterations is unknown?

  • A) for loop
  • B) while loop
  • C) nested loop
  • D) for-each loop

Answer: A Rationale: range(5) produces the sequence 0, 1, 2, 3, 4, which iterates 5 times.

Q31. What does range(3) produce?

  • A) [1, 2, 3]
  • B) [0, 1, 2]
  • C) [0, 1, 2, 3]
  • D) [1, 2] Answer: B Rationale: range(3) starts at 0 and stops before 3, producing 0, 1, 2.

Q32. Which loop type is NOT built into Python?

  • A) for
  • B) while
  • C) repeat
  • D) do-while (not native) Answer: C

Rationale: Python has no repeat or native do-while loop. It has for and while loops.

Q33. Which keyword is used to exit a loop prematurely in Python?

  • A) return
  • B) break
  • C) stop
  • D) end Answer: B Rationale: The break keyword is used to exit a loop prematurely.

Q34. In the code for item in my_list:, what does item represent?

  • A) The index of the current element
  • B) The current element being processed
  • C) The length of the list
  • D) The entire list Answer: B Rationale: In a for loop, item represents the current element being processed from the iterable.

Answer: B Rationale: The code adds the integers 5 and 10, resulting in 15.

Q37. What is the output of print(3 ** 3)?

  • A) 9
  • B) 27
  • C) 6
  • D) 18 Answer: B Rationale: The ** operator is exponentiation. 3 ** 3 = 27.

Q38. What does the continue statement do in a loop?

  • A) Exits the loop completely
  • B) Skips the current iteration and continues with the next
  • C) Restarts the loop from the beginning
  • D) Pauses the loop temporarily Answer: B

Rationale: The continue statement skips the rest of the current iteration and moves to the next iteration of the loop.

Q39. Which of the following correctly creates an infinite loop in Python?

  • A) for i in range(10):
  • B) while True:
  • C) while False:
  • D) for i in range(): Answer: B Rationale: while True: creates an infinite loop because the condition is always True. The loop will run indefinitely unless broken with break.

Q40. What is the output of the following code?

for i in range(2, 5): print(i, end=" ")
  • A) 2 3 4 5
  • B) 2 3 4
  • C) 1 2 3 4