Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) Objective Assessment 2 – Complete Practice Te, Exams of Programming Languages

Toggle sidebar
bg1
WGU E010 FOUNDATIONS OF PROGRAMMING
(PYTHON) Objective Assessment 2 – Complete
Practice Test Bank
Course: E010 – Foundations of Programming (Python)
Institution: Western Governors University (WGU)
Assessment: Objective Assessment (OA) – Final Exam
Latest Update: 2025/2026
Format: 300 practice questions with verified answers and detailed rationales
Source: Compiled from actual exam prep materials, practice test banks, and verified OA
questions
TABLE OF CONTENTS
| Section | Domain | Questions |
|-|||
| I | Variables, Data Types & Type Casting | 1–40 |
| II | Operators & Expressions | 41–70 |
| III | String Manipulation & Indexing | 71–100 |
| IV | Control Flow – Conditionals (if/elif/else) | 101–125 |
| V | Loops (for, while, break, continue) | 126–160 |
| VI | Functions & Scope | 161–195 |
| VII | Data Structures – Lists, Tuples, Dictionaries, Sets | 196–230 |
| VIII | File Handling & Input/Output | 231–255 |
| IX | Comprehensive Mixed Review | 256–300 |
SECTION I: VARIABLES, DATA TYPES & TYPE CASTING (Questions 1–40)
Question 1
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`
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) Objective Assessment 2 – Complete Practice Te and more Exams Programming Languages in PDF only on Docsity!

WGU E010 FOUNDATIONS OF PROGRAMMING

(PYTHON) Objective Assessment 2 – Complete

Practice Test Bank

Course: E010 – Foundations of Programming (Python) Institution: Western Governors University (WGU) Assessment: Objective Assessment (OA) – Final Exam Latest Update: 2025/ Format: 300 practice questions with verified answers and detailed rationales Source: Compiled from actual exam prep materials, practice test banks, and verified OA questions

TABLE OF CONTENTS

| Section | Domain | Questions | |-||| | I | Variables, Data Types & Type Casting | 1–40 | | II | Operators & Expressions | 41–70 | | III | String Manipulation & Indexing | 71–100 | | IV | Control Flow – Conditionals (if/elif/else) | 101–125 | | V | Loops (for, while, break, continue) | 126–160 | | VI | Functions & Scope | 161–195 | | VII | Data Structures – Lists, Tuples, Dictionaries, Sets | 196–230 | | VIII | File Handling & Input/Output | 231–255 | | IX | Comprehensive Mixed Review | 256–300 |

SECTION I: VARIABLES, DATA TYPES & TYPE CASTING (Questions 1–40)

Question 1 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.

Question 2 Which of the following is a valid variable name in Python?

  • A) 2ndName
  • B) my-name
  • C) my_name
  • D) class

Answer: C Rationale: Python variable names cannot start with a digit (eliminating 2ndName), cannot contain hyphens (eliminating my-name), and cannot be reserved keywords like class (eliminating class). Underscores are allowed and commonly used, so my_name is valid.

Question 3 Which of the following is a valid Boolean value in Python?

  • A) "True"
  • B) true
  • C) True
  • D) 1

Answer: C Rationale: Python's Boolean values are True and False (capitalized). "True" is a string, true is not a valid keyword (Python is case-sensitive), and 1 is an integer that evaluates to True in a Boolean context but is not itself a Boolean.

Question 4 What is the output of bool(0)?

  • A) True
  • B) False

Answer: C Rationale: int() cannot convert a string representing a floating-point number directly. It will raise a ValueError because the string contains a decimal point.

Question 8 What is the output of print(type(10 / 2))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: B Rationale: In Python, the division operator / always returns a float, even if the numbers divide evenly. 10 / 2 evaluates to 5.0, and type(5.0) returns ``. Python does not have a separate double type.

Question 9 What is the output of print(type(10 // 2))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: A Rationale: The floor division operator // returns an integer result (if both operands are integers) or a float if any operand is a float. 10 // 2 evaluates to 5, which is an int.

Question 10 Which data type is immutable in Python?

  • A) list
  • B) dict
  • C) set
  • D) tuple

Answer: D

Rationale: Tuples cannot be changed after creation, making them immutable. Lists, dictionaries, and sets are all mutable data types that can be modified after creation.

Question 11 What is the output of print(type([]))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: B Rationale: [] creates an empty list, so type([]) returns ``.

Question 12 Which of the following creates a dictionary in Python?

  • A) []
  • B) {}
  • C) ()
  • D) set()

Answer: B Rationale: {} creates an empty dictionary. [] creates a list, () creates a tuple, and set() creates an empty set.

Question 13 What is the output of print(type(()))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: A Rationale: () creates an empty tuple, so type(()) returns ``.

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: D Rationale: True is a Boolean value, so type(True) returns ``.

Question 18 Which of the following is NOT a valid data type in Python?

  • A) int
  • B) float
  • C) double
  • D) str

Answer: C Rationale: Python does not have a double data type. Floating-point numbers are represented by the float type.

Question 19 What is the output of print(type(None))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: D Rationale: None is a special constant in Python representing the absence of a value. Its type is ``.

Question 20 What is the result of int(3.14)?

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

Answer: A Rationale: The int() function truncates the decimal portion of a floating-point number, converting it to an integer. int(3.14) returns 3.

Question 21 What is the result of float(5)?

  • A) 5
  • B) 5.0
  • C) Error
  • D) "5"

Answer: B Rationale: The float() function converts an integer to a floating-point number. float(5) returns 5.0.

Question 22 What is the result of str(100)?

  • A) 100
  • B) "100"
  • C) Error
  • D) '100'

Answer: B Rationale: The str() function converts a value to a string. str(100) returns the string "100".

Question 23 What is the output of print(bool(1))?

  • A) True
  • B) False
  • C) 1
  • D) Error

Answer: A

Question 27 What is the output of print(bool([]))?

  • A) True
  • B) False
  • C) []
  • D) Error

Answer: B Rationale: An empty list evaluates to False in a Boolean context.

Question 28 What is the output of print(bool([1, 2, 3]))?

  • A) True
  • B) False
  • C) [1, 2, 3]
  • D) Error

Answer: A Rationale: A non-empty list evaluates to True in a Boolean context.

Question 29 Which of the following is a valid way to create a variable with a floating-point value?

  • A) x = 5
  • B) x = 5.0
  • C) x = "5.0"
  • D) x = True

Answer: B Rationale: 5.0 is a floating-point literal. 5 is an integer, "5.0" is a string, and True is a Boolean.

Question 30 What is the output of print(type(5.0))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: B Rationale: 5.0 is a floating-point number, so type(5.0) returns ``.

Question 31 What is the output of print(int(True))?

  • A) 1
  • B) 0
  • C) True
  • D) Error

Answer: A Rationale: In Python, True is represented internally as 1. int(True) returns 1.

Question 32 What is the output of print(int(False))?

  • A) 1
  • B) 0
  • C) False
  • D) Error

Answer: B Rationale: In Python, False is represented internally as 0. int(False) returns 0.

Question 33 What is the output of print(bool(0.0))?

  • A) True
  • B) False
  • C) 0.0
  • D) Error

Question 37 What is the output of print(10 // 3)?

  • A) 3
  • B) 3.3333333333333335
  • C) 3.0
  • D) Error

Answer: A Rationale: The // operator performs floor division, returning the largest integer less than or equal to the result. 10 // 3 returns 3.

Question 38 What is the output of print(10 % 3)?

  • A) 3
  • B) 1
  • C) 0
  • D) 3.333...

Answer: B Rationale: The % operator returns the remainder of the division. 10 % 3 returns 1 because 3 goes into 10 three times with a remainder of 1.

Question 39 Which of the following correctly converts a string to a float?

  • A) float("3.14")
  • B) int("3.14")
  • C) str("3.14")
  • D) bool("3.14")

Answer: A Rationale: The float() function can convert a string representing a floating-point number to a float. int("3.14") would raise an error because of the decimal point.

Question 40 What is the output of print(type(int("100")))?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Answer: A Rationale: int("100") converts the string "100" to the integer 100. type(100) returns ``.

SECTION II: OPERATORS & EXPRESSIONS (Questions 41–70)

Question 41 What is the output of print(5 + 10)?

  • A) 510
  • B) 15
  • C) Error
  • D) 5 10

Answer: B Rationale: The + operator performs arithmetic addition when both operands are integers. 5 + 10 equals 15.

Question 42 What is the output of print("5" + "10")?

  • A) 15
  • B) "510"
  • C) 510
  • D) Error

Answer: C Rationale: When both operands are strings, the + operator performs concatenation. "5" + "10" results in the string "510".

Question 46 What is the output of print(10 // 4)?

  • A) 2
  • B) 2.5
  • C) 3
  • D) Error

Answer: A Rationale: The // operator performs floor division. 10 // 4 returns 2.

Question 47 What is the output of print(5 == 5)?

  • A) True
  • B) False
  • C) 5
  • D) Error

Answer: A Rationale: The == operator compares two values for equality. 5 == 5 returns True.

Question 48 What is the output of print(5 != 5)?

  • A) True
  • B) False
  • C) 5
  • D) Error

Answer: B Rationale: The != operator checks if two values are not equal. 5 != 5 returns False.

Question 49 What is the output of print(5 > 3)?

  • A) True
  • B) False

- C) 5

  • D) Error

Answer: A Rationale: The > operator checks if the left value is greater than the right value. 5 > 3 returns True.

Question 50 What is the output of print(5 < 3)?

  • A) True
  • B) False
  • C) 5
  • D) Error

Answer: B Rationale: The < operator checks if the left value is less than the right value. 5 < 3 returns False.

Question 51 What is the output of print(5 >= 5)?

  • A) True
  • B) False
  • C) 5
  • D) Error

Answer: A Rationale: The >= operator checks if the left value is greater than or equal to the right value. 5 >= 5 returns True.

Question 52 What is the output of print(5 <= 3)?

  • A) True
  • B) False
  • C) 5
  • D) Error

Rationale: The not operator returns the opposite Boolean value. not True returns False.

Question 56 What is the output of print(3 + 4 * 2)?

  • A) 14
  • B) 11
  • C) 10
  • D) Error

Answer: B Rationale: Python follows operator precedence. Multiplication is performed before addition: 4 * 2 = 8, then 3 + 8 = 11.

Question 57 What is the output of print((3 + 4) * 2)?

  • A) 14
  • B) 11
  • C) 10
  • D) Error

Answer: A Rationale: Parentheses have the highest precedence. (3 + 4) = 7, then 7 * 2 = 14.

Question 58 What is the output of print(10 - 3 * 2)?

  • A) 14
  • B) 4
  • C) 7
  • D) Error

Answer: B Rationale: Multiplication is performed before subtraction: 3 * 2 = 6, then 10 - 6 = 4.

Question 59 What is the output of print(10 % 3 == 1)?

  • A) True
  • B) False
  • C) 1
  • D) Error

Answer: A Rationale: 10 % 3 returns 1. The expression 1 == 1 returns True.

Question 60 What is the output of print(2 * 3 2)?

  • A) 36
  • B) 18
  • C) 12
  • D) Error

Answer: B Rationale: Exponentiation has higher precedence than multiplication. 3 2 = 9, then 2 * 9 = 18.

Question 61 What is the output of print(2 3 2)?

  • A) 64
  • B) 512
  • C) 36
  • D) Error

Answer: B Rationale: Exponentiation is right-associative in Python. 3 2 = 9, then 2 9 = 512.

Question 62 What is the output of print(5 + "5")?

  • A) 10