Docsity

ITP 150 – PYTHON PROGRAMMING MIDTERM EXAM 2026_2027 — PRACTICE QUESTION BANK (300 QUESTION, Exams of Javascript programming

Toggle sidebar
bg1
ITP 150 – PYTHON PROGRAMMING
MIDTERM EXAM 2026/2027 — PRACTICE QUESTION BANK
(300 QUESTIONS)
Format: Question / Four Options / Correct Answer /
Explanation
Based on: NOVA ITP 150 Course Content Summary and
standard Python 3 curriculum
SECTION 1: PYTHON BASICS, SHELL, AND IDE (Questions 1–25)
1. What does IDE stand for in Python programming?
A. Integrated Development Environment
B. Interactive Debugging Engine
C. Internal Data Exchange
D. Integrated Data Editor
Answer: A
Explanation: An IDE (Integrated Development Environment) is software that provides
comprehensive facilities for software development, including a code editor, debugger, and
build tools.
2. Which of the following is included when you install Python?
A. The IDLE integrated development environment
B. The pip package manager
C. The Python documentation
D. All of the above
Answer: D
Explanation: A standard Python installation includes the IDLE IDE, the pip package
manager, and the Python documentation.
3. What is the Python Shell primarily used for?
A. Writing and running complete programs
B. Exploring language constructs interactively
C. Debugging only
D. Managing packages
Answer: B
Explanation: The Python Shell allows you to type Python statements and see immediate
results, making it useful for initial exploration of language constructs.
4. What does the pip package manager do?
A. Compiles Python code
B. Installs and manages additional packages from PyPI
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 ITP 150 – PYTHON PROGRAMMING MIDTERM EXAM 2026_2027 — PRACTICE QUESTION BANK (300 QUESTION and more Exams Javascript programming in PDF only on Docsity!

ITP 150 – PYTHON PROGRAMMING

MIDTERM EXAM 2026/2027 — PRACTICE QUESTION BANK

(300 QUESTIONS)

Format: Question / Four Options / Correct Answer /

Explanation

Based on: NOVA ITP 150 Course Content Summary and

standard Python 3 curriculum

SECTION 1: PYTHON BASICS, SHELL, AND IDE (Questions 1–25)

  1. What does IDE stand for in Python programming? A. Integrated Development Environment B. Interactive Debugging Engine C. Internal Data Exchange D. Integrated Data Editor Answer: A Explanation: An IDE (Integrated Development Environment) is software that provides comprehensive facilities for software development, including a code editor, debugger, and build tools.
  2. Which of the following is included when you install Python? A. The IDLE integrated development environment B. The pip package manager C. The Python documentation D. All of the above Answer: D Explanation: A standard Python installation includes the IDLE IDE, the pip package manager, and the Python documentation.
  3. What is the Python Shell primarily used for? A. Writing and running complete programs B. Exploring language constructs interactively C. Debugging only D. Managing packages Answer: B Explanation: The Python Shell allows you to type Python statements and see immediate results, making it useful for initial exploration of language constructs.
  4. What does the pip package manager do? A. Compiles Python code B. Installs and manages additional packages from PyPI

C. Runs Python scripts D. Creates virtual environments Answer: B Explanation: pip allows you to install and manage additional packages from the Python Package Index (PyPI) or other sources.

  1. How do you create a single-line comment in Python? A. // This is a comment B. This is a comment C. / This is a comment / D. -- This is a comment Answer: B Explanation: In Python, a single-line comment begins with the hash symbol () and extends to the end of the line.
  2. What is the standard Python coding style for variable names? A. camelCase B. PascalCase C. snake_case D. SCREAMING_SNAKE_CASE Answer: C Explanation: PEP 8, the official Python style guide, recommends snake_case (lowercase words separated by underscores) for variable names.
  3. What is a Python module? A. A built-in function B. A file containing Python code that can be imported C. A type of variable D. A syntax error Answer: B Explanation: A module is a file containing Python definitions and statements that can be imported into other programs.
  4. What is source code? A. The compiled version of a program B. The instructions in a program, stored in a file C. The output of a program D. The memory used by a program Answer: B Explanation: Source code is the set of instructions written in a programming language, stored in a file, which can be read and edited.
  5. What is debugging? A. Writing new code B. Tracking down programming errors and correcting them C. Running a program D. Installing packages Answer: B
  1. What is a program? A. A sequence of instructions that specifies how to perform a computation B. A type of computer C. A hardware component D. An operating system Answer: A Explanation: A program is a set of instructions that tells the computer how to perform a specific task.
  2. Which of the following is a feature of a good Python coding environment? A. Debugging support B. Syntax highlighting C. Automatic code formatting D. All of the above Answer: D Explanation: A good coding environment includes debugging support, syntax highlighting, and automatic code formatting, among other features.
  3. What is the purpose of comments in code? A. To make the program run faster B. To explain to readers what the program is doing C. To create variables D. To import modules Answer: B Explanation: Comments are written in natural language to help people understand the code; they are ignored by the interpreter.
  4. What is source or version control? A. An IDE feature that helps track and manage changes to code B. A type of variable C. A Python built-in function D. A syntax error Answer: A Explanation: Version control (e.g., Git) tracks changes to code over time, allowing collaboration and rollback.
  5. What does the Python interpreter do? A. Translates the entire program at once B. Executes code line by line C. Compiles code to machine language D. Manages packages Answer: B Explanation: The Python interpreter executes code line by line, which is why Python is called an interpreted language.
  6. What is the Python Standard Library? A. A collection of modules built into Python B. A third-party package

C. A type of IDE D. A syntax error Answer: A Explanation: The Python Standard Library is a collection of modules (like math, random, calendar) included with every Python installation.

  1. Which of the following is a valid string literal in Python? A. "Hello, World!" B. 'Hello, World!' C. Both A and B D. Hello, World! Answer: C Explanation: Python allows strings to be enclosed in either single quotes or double quotes.
  2. What is the output of print("Hello" + "World")? A. Hello World B. HelloWorld C. Hello+World D. Error Answer: B Explanation: The + operator concatenates strings without adding a space, producing "HelloWorld".
  3. What is the output of print("Hello", "World")? A. HelloWorld B. Hello World C. Hello,World D. Error Answer: B Explanation: When multiple arguments are passed to print(), they are separated by a space by default.
  4. What is the output of print("apple", "banana", "cherry", sep=", ")? A. applebananacherry B. apple banana cherry C. apple, banana, cherry D. apple;banana;cherry Answer: C Explanation: The sep parameter specifies the separator between arguments; here it is a comma and a space.
  5. What is the output of print("1", "2", "3", sep="-", end="!") followed by print("Go!")? A. 1-2-3!Go! B. 1-2-3Go! C. 1 2 3!Go! D. 123!Go! Answer: A
  1. What is the data type of the variable x after x = 20.5? A. int B. float C. str D. bool Answer: B Explanation: The number 20.5 has a decimal point, making it a float.
  2. What is the data type of the variable x after x = True? A. int B. float C. str D. bool Answer: D Explanation: True is a Boolean literal.
  3. Which of the following is an invalid variable name in Python? A. my_var B. _myvar C. 1variable D. myVar Answer: C Explanation: Variable names cannot begin with a digit. 1variable is invalid.
  4. What is the result of 232 in Python? A. 64 B. 512 C. 12 D. 18 Answer: B Explanation: The exponentiation operator `` is right-associative: 2(32) = 29 = 512.
  5. What is the result of 10 % 3? A. 3 B. 1 C. 0 D. 3. Answer: B Explanation: % is the modulus operator, which returns the remainder of division. 10 ÷ 3 = 3 remainder 1.
  6. What is the result of 10 // 3? A. 3. B. 3 C. 1 D. 0 Answer: B

Explanation: // is floor division, which returns the integer quotient. 10 // 3 = 3.

  1. What is the result of 10 / 3? A. 3 B. 3.333... C. 1 D. 0 Answer: B Explanation: / is true division, which returns a float. 10 / 3 = 3.333....
  2. What is the result of 10 - 2 3 + 4 2 / 2? A. 12. B. 10 C. 14 D. 8 Answer: A Explanation: Following order of operations: 10 - 6 + 4 = 12.0 (the division produces a float).
  3. What is the order of operations in Python (from highest to lowest precedence)? A. Parentheses, exponentiation, multiplication/division, addition/subtraction B. Addition, multiplication, exponentiation, parentheses C. Exponentiation, parentheses, addition, multiplication D. Multiplication, addition, parentheses, exponentiation Answer: A Explanation: Python follows PEMDAS: Parentheses, Exponents, Multiplication/Division (left- to-right), Addition/Subtraction (left-to-right).
  4. Which of the following is a valid augmented assignment operator? A. += B. -= C. = D. All of the above Answer: D Explanation: Augmented assignment operators (+=, -=, =, /=, etc.) combine an operation with assignment.
  5. What is the result of x = 5; x += 3? A. 8 B. 5 C. 3 D. 2 Answer: A Explanation: x += 3 is equivalent to x = x + 3, so x becomes 8.
  6. What is the result of bool(1)? A. True B. False C. 1

B. False C. TrueFalse D. Error Answer: A Explanation: or returns True if at least one operand is True.

  1. What is the result of not True? A. True B. False C. TrueFalse D. Error Answer: B Explanation: not negates the Boolean value, so not True is False.
  2. What is a literal in Python? A. A value written directly in the code (e.g., 5, "Hello", True) B. A variable C. A function D. A module Answer: A Explanation: A literal is a fixed value written directly in the source code, such as a number, string, or Boolean.
  3. What is the result of round(3.14159, 2)? A. 3. B. 3. C. 3. D. 3. Answer: A Explanation: round(number, ndigits) rounds to the specified number of decimal places. 3.14159 rounded to 2 decimals is 3.14.
  4. What is the result of int(3.9)? A. 3 B. 4 C. 3. D. Error Answer: A Explanation: int() truncates the decimal part, so int(3.9) is 3.
  5. What is the result of float(5)? A. 5 B. 5. C. 0 D. Error Answer: B Explanation: float(5) converts the integer 5 to the float 5.0.
  1. What is the result of str(42)? A. 42 B. "42" C. '42' D. Error Answer: B Explanation: str(42) converts the integer 42 to the string "42".
  2. What is the result of type(5.0)? A. B. C. D. Answer: B Explanation: 5.0 is a float, so type(5.0) returns ``.

SECTION 3: INPUT, OUTPUT, AND STRINGS (Questions 56–85)

  1. What does the input() function do? A. Reads input from the keyboard as a string B. Prints output to the console C. Converts input to an integer D. Reads a file Answer: A Explanation: input() reads a line of text from the console and returns it as a string.
  2. What data type does input() always return? A. int B. float C. str D. bool Answer: C Explanation: input() always returns a string, even if the user enters a number. Conversion is needed for numeric operations.
  3. How do you convert user input to an integer? A. int(input("Enter a number: ")) B. input(int("Enter a number: ")) C. str(input("Enter a number: ")) D. float(input("Enter a number: ")) Answer: A Explanation: Wrap input() with int() to convert the string to an integer.
  4. What is the output of print("Python", "is" + "fun!")? A. Python isfun! B. Python is fun!
  1. What does the title() method do? A. Capitalizes the first letter of each word B. Converts to uppercase C. Converts to lowercase D. Removes whitespace Answer: A Explanation: "hello world".title() returns "Hello World".
  2. What does the strip() method do? A. Removes whitespace from both ends of a string B. Removes all whitespace from a string C. Converts to uppercase D. Splits the string Answer: A Explanation: strip() removes leading and trailing whitespace, not internal whitespace.
  3. What does the format() method do? A. Formats a string by substituting values into placeholders B. Converts to uppercase C. Removes whitespace D. Splits the string Answer: A Explanation: format() allows you to insert values into a string using {} placeholders.
  4. What is the output of "Hello {}".format("World")? A. Hello World B. Hello {World} C. HelloWorld D. Error Answer: A Explanation: The {} placeholder is replaced by the argument "World", producing "Hello World".
  5. What is the output of "{} + {} = {}".format(2, 3, 5)? A. 2 + 3 = 5 B. 2+3= C. 2 + 3 = 5 D. Error Answer: A Explanation: The placeholders are filled in order with the arguments, producing "2 + 3 = 5".
  6. What is the output of "Hello"[0]? A. H B. e C. o D. Hello Answer: A Explanation: String indexing starts at 0, so "Hello"[0] is 'H'.
  1. What is the output of "Hello"[-1]? A. H B. e C. o D. Hello Answer: C Explanation: Negative indexing starts from the end; -1 refers to the last character, 'o'.
  2. What is the output of "Hello"[1:4]? A. ell B. Hel C. llo D. lo Answer: A Explanation: Slicing [1:4] returns characters from index 1 up to (but not including) index 4: 'e', 'l', 'l' → "ell".
  3. What is the output of "Hello"[:3]? A. Hel B. Hello C. lo D. H Answer: A Explanation: [:3] takes characters from the start up to index 2: "Hel".
  4. What is the output of "Hello"[2:]? A. llo B. He C. Hel D. o Answer: A Explanation: [2:] takes characters from index 2 to the end: "llo".
  5. What does the in operator do when used with strings? A. Checks if a substring exists within a string B. Concatenates strings C. Compares string lengths D. Converts to uppercase Answer: A Explanation: "ell" in "Hello" returns True because "ell" is a substring of "Hello".
  6. What is the output of "a" in "abc"? A. True B. False C. a D. Error Answer: A

D. -

Answer: A Explanation: find() returns the index of the first occurrence of the substring; the first 'l' is at index 2.

  1. What is the output of "Hello".count("l")? A. 2 B. 3 C. 1 D. 0 Answer: A Explanation: count() returns the number of non-overlapping occurrences of the substring; there are two 'l's.
  2. What is the output of "Hello".startswith("He")? A. True B. False C. He D. Error Answer: A Explanation: startswith() checks if the string begins with the specified prefix.
  3. What is the output of "Hello".endswith("lo")? A. True B. False C. lo D. Error Answer: A Explanation: endswith() checks if the string ends with the specified suffix.

SECTION 4: IF STATEMENTS AND CONDITIONALS (Questions 86–110)

  1. What is the correct syntax for an if statement in Python? A. if x > 5: B. if (x > 5) { C. if x > 5 then D. if x > 5; Answer: A Explanation: Python uses a colon at the end of the if condition and indentation for the block.
  2. Which of the following is a relational operator in Python? A. > B. >= C. == D. All of the above Answer: D

Explanation: Relational operators include >, <, >=, <=, ==, and !=.

  1. What is the result of 5 > 3? A. True B. False C. 5 D. 3 Answer: A Explanation: 5 is greater than 3, so the expression evaluates to True.
  2. What is the result of 5 == 5.0? A. True B. False C. 5 D. Error Answer: A Explanation: Python considers 5 and 5.0 equal in value, so == returns True.
  3. What is the result of 5 != 5? A. True B. False C. 5 D. Error Answer: B Explanation: != checks for inequality; since 5 equals 5, the result is False.
  4. What does the elif keyword do? A. Provides an alternative condition to check if the previous if was false B. Ends the if statement C. Is another name for else D. Starts a loop Answer: A Explanation: elif (else if) allows checking multiple conditions in sequence.
  5. What is the output of the following code? python x = 10 if x > 5: print("A") elif x > 3: print("B") else: print("C")

A. A B. B C. C D. A and B

  1. What is the result of True and False or True? A. True B. False C. TrueFalse D. Error Answer: A Explanation: and has higher precedence than or: (True and False) or True → False or True → True.
  2. What is the result of not (True and False)? A. True B. False C. TrueFalse D. Error Answer: A Explanation: True and False is False; not False is True.
  3. Which Python operator is right-associative? A. (exponentiation) B. `+` (addition) C. (multiplication) D. = (assignment) Answer: A Explanation: The exponentiation operator `` is right-associative, so 232 is 2(32) = 512.
  4. What is a Boolean expression? A. An expression that evaluates to True or False B. An expression that evaluates to a number C. An expression that evaluates to a string D. An expression that cannot be evaluated Answer: A Explanation: Boolean expressions use relational and logical operators and produce a bool result.
  5. What is the output of print(3 > 2 > 1)? A. True B. False C. 3 D. Error Answer: A Explanation: Chained comparisons are evaluated as (3 > 2) and (2 > 1), both of which are True.
  6. What is the output of print(1 < 2 < 3 < 4)? A. True B. False C. 1

D. Error Answer: A Explanation: Chained comparisons evaluate to True if all individual comparisons are True.

  1. What is the output of print(5 if 10 > 5 else 0)? A. 5 B. 10 C. 0 D. Error Answer: A Explanation: This is a conditional expression; since the condition is True, it returns 5.
  2. How do you check if a value is not in a list? A. value not in list B. value != list C. value <> list D. not value in list Answer: A Explanation: The not in operator checks for absence from a collection.
  3. What is the result of 5 in [1, 3, 5, 7]? A. True B. False C. 5 D. Error Answer: A Explanation: The value 5 is an element of the list, so in returns True.
  4. What is the result of 2 in [1, 3, 5, 7]? A. True B. False C. 2 D. Error Answer: B Explanation: The value 2 is not in the list, so in returns False.
  5. What is the output of the following code? python x = 15 if x % 2 == 0: print("Even") elif x % 3 == 0: print("Divisible by 3") else: print("Other")

A. Even B. Divisible by 3