- Học kỳ
- SU2026
- Thời Gian
- 4/8/26
- Loại tài liệu
- FE
- Mã Đề
- PFP191_SU26_RE_948748
PFP191_SU26_RE_948748
Bộ câu hỏi ôn tập môn lập trình Python PFP191
Tài liệu này tổng hợp hệ thống câu hỏi trắc nghiệm ôn tập cho môn học lập trình Python với các tình huống lập trình và bài toán thực tế đa dạng. Nội dung bao gồm kiến thức về lập trình hướng đối tượng như kế thừa lớp, phương thức khởi tạo và tính đa hình. Bên cạnh đó, người học còn được củng cố các kỹ năng xử lý chuỗi, thao tác với danh sách, từ điển, cũng như các kỹ thuật xử lý tệp và ngoại lệ. Đây là nguồn tài liệu hữu ích giúp học sinh kiểm tra và củng cố hiểu biết về cú pháp cũng như tư duy logic trong Python.PFP191_SU26_RE_948748
PFP191_SU26_RE_948748 | Multiple Choice
Question 1
(Choose 1 answer)
What's the output of the following code snippet?
class Dog:
def walk(self):
return "*walking*"
def speak(self):
return "Woof!"
class JackRussellTerrier(Dog):
def talk(self):
return super().speak()
bobo = JackRussellTerrier()
bobo.talk()
A. Woof!
B. *walking*
C. CanineError: Tail curvature exceeded
PFP191_SU26_RE_948748 | Multiple Choice
Question 2
(Choose 1 answer)
What will be the output of the following code?
class Student:
def __init__(self, name, age):
self.name = name
self.__age = age # Private attribute
s = Student("Alice", 20)
print(s.__age)
A. 20
B. None
C. Error: AttributeError
D. "Alice"
PFP191_SU26_RE_948748 | Multiple Choice
Question 3
(Choose 1 answer)
What is the purpose of the __init__ method in Python classes?
A. To define a function inside a class
B. To initialize an object when it is created
C. To delete an object
D. To define a private variable
PFP191_SU26_RE_948748 | Multiple Choice
Question 4
(Choose 1 answer)
What is inheritance in object-oriented programming, and how does it work in Python?
A. Inheritance allows us to create new classes (child classes) based on existing classes (parent classes), inheriting their properties and behaviours while adding new features or modifying existing ones.
B. Inheritance is a way to create copies of existing objects.
C. Inheritance is a method for organising code into separate modules.
D. Inheritance is a technique for securing data within a program.
PFP191_SU26_RE_948748 | Multiple Choice
Question 5
(Choose 1 answer)
What is polymorphism?
A. Ability of different objects to respond to the same method call differently
B. Hiding implementation details
C. Creating objects from a class
D. Restricting access to attributes
PFP191 Multiple Choice Questions
PFP191_SU26_RE_948748 | Multiple Choice
Question 6
(Choose 1 answer)
In which of the following does the CricketFan class correctly inherit from the PartyAnimal class?
A. from party import PartyAnimal
B. class CricketFan(PartyAnimal)
C. an = PartyAnimal()
D. CricketFan = PartyAnimal()
PFP191_SU26_RE_948748 | Multiple Choice
Question 7
(Choose 1 answer)
Which of the following statements is true?
A. A class is blueprint for the object.
B. You can only make a single object from the given class.
C. Both statements are true.
D. Neither statement is true.
PFP191_SU26_RE_948748 | Multiple Choice
Question 8
(Choose 1 answer)
Which keyword is used to create a child class?
A. extends
B. inherits
C. superclass
D. class ChildClass(ParentClass)
PFP191_SU26_RE_948748 | Multiple Choice
Question 9
(Choose 1 answer)
Which method is used to set up initial values for the object?
A. __init__
B. __new__
C. __create__
D. __start__
PFP191_SU26_RE_948748 | Multiple Choice
Question 10
(Choose 1 answer)
What is the output of the following code snippet?
text = "abrdabrab"
pattern = "ab"
count = 0
for i in range(len(text) - len(pattern) + 1):
if text[i:i + len(pattern)] == pattern:
count += 1
print(count)
A. 3
B. 2
C. 0
D. 1
PFP191 Multiple Choice Questions
PFP191_SU26_RE_948748 | Multiple Choice
Question 11
(Choose 1 answer)
What will be the output of the following code?
s = "ababadcdcdcdcdtyty"
print(s[::-2]
A. yydddddbb
B. ytytdcdcdcdcdababa
C. aaacccctt
D. ytdcda
PFP191_SU26_RE_948748 | Multiple Choice
Question 12
(Choose 1 answer)
What will be the output of the following code?
s = "abcdefg"
print(s[1::2]
A. bdf
B. aceg
C. bcefg
D. bcdfg
PFP191_SU26_RE_948748 | Multiple Choice
Question 13
(Choose 1 answer)
Why is the statement greeting[0] = 'J' invalid if greeting = "Hello"?
A. Because strings are immutable in Python.
B. Because Python doesn't allow reassignment.
C. Because index 0 is reserved.
D. Because greeting must be a list.
PFP191_SU26_RE_948748 | Multiple Choice
Question 14
(Choose 1 answer)
What will the below script print out?
s1 = "retake"
s2 = "the exam"
s1[0] = 'R'
print(s1 + s2)
A. Retake the exam
B. Retakethe exam
C. retakethe exam
D. The TypeError will be raised.
PFP191_SU26_RE_948748 | Multiple Choice
Question 15
(Choose 1 answer)
What is the output of the following snippet code?
string = "OpenAI is awesome"
parts = string.split("is")
result = len(parts)
print(result)
A. 2
B. 1
C. 3
D. 4
PFP191 SU26 FE RE Questions 16 to 20
PFP191_SU26_RE_948748 | Multiple Choice
Question 16
(Choose 1 answer)
What is the result of the following Python code?
word = 'brontosaurus'
d = dict()
for c in word:
d[c] = d.get(c, 0) + 1
print(d)
A. {'b': 1, 'r': 2, 'o': 2, 'n': 1, 't': 1, 's': 2, 'a': 1, 'u': 2}
B. {'b': 1, 'r': 2, 'o': 1, 'n': 1, 't': 1, 's': 1, 'a': 1, 'u': 1}
C. {'b': 1, 'r': 2, 'o': 2, 'n': 1, 't': 1, 's': 1, 'a': 1, 'u': 1}
D. {'b': 1, 'r': 1, 'o': 1, 'n': 1, 't': 1, 's': 1, 'a': 1, 'u': 1}
PFP191_SU26_RE_948748 | Multiple Choice
Question 17
(Choose 1 answer)
What is a dictionary in Python?
A. A mutable data structure that stores key-value pairs, where each key maps to a value
B. An immutable data structure that stores key-value pairs, where each key maps to a value
C. A sequence of values
D. A sequence of characters stored in permanent storage like a hard drive
PFP191_SU26_RE_948748 | Multiple Choice
Question 18
(Choose 1 answer)
Which method returns a list of tuples, where each tuple is a key-value pair from the dictionary?
A. items()
B. keys()
C. values()
D. pairs()
PFP191_SU26_RE_948748 | Multiple Choice
Question 19
(Choose 1 answer)
What will be the output of the following code if the file test.txt contains multiple lines of text?
with open('test.txt', 'r') as file:
for line in file:
print(line.strip())
A. All lines of the file without leading/trailing whitespace
B. All lines of the file with leading/trailing whitespace
C. The first line of the file without leading/trailing whitespace
D. None of the others
PFP191_SU26_RE_948748 | Multiple Choice
Question 20
(Choose 1 answer)
Which function is used to read the entire contents of a file?
A. open()
B. read()
C. close()
D. B and C are both correct
PFP191 SU26 FE RE Questions 21 to 25
PFP191_SU26_RE_948748 | Multiple Choice
Question 21
(Choose 1 answer)
What will be the output of the following code if the file test.txt does not exist?
try:
with open('test.txt', 'r') as file:
content = file.read()
except FileNotFoundError:
content = 'File not found'
print(content)
A. File not found
B. An error message
C. An empty string
D. None
PFP191_SU26_RE_948748 | Multiple Choice
Question 22
(Choose 1 answer)
Which of the following is not a method of opening files?
A. Replace
B. Append
C. Read
D. Write
PFP191_SU26_RE_948748 | Multiple Choice
Question 23
(Choose 1 answer)
What does the following Python code do?
fhand = open('mbox-short.txt')
inp = fhand.read()
A. Checks to see if the file exists and can be written
B. Turns the text in the file into a graphic image like a PNG or JPG
C. Reads the entire file into the variable inp as a string
D. Prompts the user for a file name
PFP191_SU26_RE_948748 | Multiple Choice
Question 24
(Choose 1 answer)
Which of the following is a correct way to open a file and ensure it is closed properly?
A. with open("file.txt", "r") as file:
B. open("file.txt", "r").close()
C. file = open("file.txt", "r")
D. open("file.txt", "r", autoclose=True)
PFP191_SU26_RE_948748 | Multiple Choice
Question 25
(Choose 1 answer)
After the line x = 123 executes in Python, the variable x with the value 123 will be stored in ______
A. Central processing unit
B. Main Memory
C. Secondary Memory
D. Input Devices
E. Output Devices
PFP191 SU26 Final Exam Multiple Choice Questions 26 to 30
PFP191_SU26_RE_948748 | Multiple Choice
Question 26
(Choose 1 answer)
In Object Oriented Programming, what is another name for the attributes of an object?
A. Portions
B. Messages
C. Forms
D. Fields
PFP191_SU26_RE_948748 | Multiple Choice
Question 27
(Choose 1 answer)
What will be the output of the following code?
a = [1, 2, 3]
a.append([4, 5]
print(a)
A. [1, 2, 3, 4, 5]
B. [1, 2, 3, [4, 5]]
C. [1, 2, 3, (4, 5)]
D. t[1:3]
PFP191_SU26_RE_948748 | Multiple Choice
Question 28
(Choose 1 answer)
What Python function would you use if you wanted to prompt the user for a file name to open?
A. input()
B. file_input()
C. gets()
D. do()
PFP191_SU26_RE_948748 | Multiple Choice
Question 29
(Choose 1 answer)
In Python, the byte code generated by the compiler is executed by which component?
A. Interpreter
B. Compiler
C. CPU
D. GPU
PFP191_SU26_RE_948748 | Multiple Choice
Question 30
(Choose 1 answer)
Which of the following is a reserved word in Python?
A. break
B. val
C. exception
D. assign
PFP191 Multiple Choice Questions
PFP191_SU26_RE_948748 | Multiple Choice
Question 31
(Choose 1 answer)
What happens if you try to assign a value to an element in a tuple?
A. The tuple is automatically converted to a list
B. The element value is updated
C. A TypeError is thrown
D. A ValueError is thrown
PFP191_SU26_RE_948748 | Multiple Choice
Question 32
(Choose 1 answer)
Consider this assignment statement:
a, b, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)[1::3]
Following execution of this statement, what is the value of b:
A. 2
B. 4
C. 5
D. 6
PFP191_SU26_RE_948748 | Multiple Choice
Question 33
(Choose 1 answer)
What is the key difference between a tuple and a list in Python?
A. Tuples are immutable, meaning their elements cannot be modified after creation. Lists are mutable.
B. Tuples are ordered and lists are unordered.
C. Tuples can contain different data types and lists can only contain the same data type.
D. Tuples are used for storing single values and lists are used for storing multiple values.
PFP191_SU26_RE_948748 | Multiple Choice
Question 34
(Choose 1 answer)
What is a good description of the following bit of Python code?
zork = 0
for thing in [9, 41, 12, 3, 74, 15] :
zork = zork + thing
print('After', zork)
A. Sum all the elements of a list
B. Find the smallest item in a list
C. Compute the average of the elements in a list
D. Count all of the elements in a list
PFP191_SU26_RE_948748 | Multiple Choice
Question 35
(Choose 1 answer)
What is the purpose of the 'continue' statement in a Python loop?
A. It immediately exits the current function.
B. It stops the loop and moves to the first statement after the loop.
C. It raises an error to signal an unexpected condition.
D. It immediately jumps to the top of the loop and starts the next iteration.
PFP191 SU26 FE RE Questions 36 to 40
PFP191_SU26_RE_948748 | Multiple Choice
Question 36
(Choose 1 answer)
Consider the following Python commands:
int('32')
int('Hello')
Choose the correct statement about the results of these commands:
A. The first command returns 32, and the second command raises a 'ValueError'
B. Both commands successfully return an integer
C. The first command returns 32, and the second command returns 0
D. The first command raises an error, and the second command returns 32
PFP191_SU26_RE_948748 | Multiple Choice
Question 37
(Choose 1 answer)
What happens if the condition in a while loop is always True?
A. The loop never terminates
B. The loop skips the condition
C. The loop executes for a fixed number of iterations
D. The loop executes once
PFP191_SU26_RE_948748 | Multiple Choice
Question 38
(Choose 1 answer)
What will the following Python program print out?
def greet(lang):
if lang == 'es':
return 'Hola'
elif lang == 'fr':
return 'Bonjour'
else:
return 'Hello'
print(greet('fr'),'Michael')
A. Bonjour Michael
B. def Michael
C. Hello Michael
D. Hola
Bonjour
Hello
PFP191_SU26_RE_948748 | Multiple Choice
Question 39
(Choose 1 answer)
How can you use the del statement to remove all elements from the list after the first one?
A. del lst[1:]
B. del lst[:-1]
C. del lst[:1]
D. del lst[-1]
PFP191_SU26_RE_948748 | Multiple Choice
Question 40
(Choose 1 answer)
How do you add an element to the end of a list in Python?
A. lst.add(element)
B. lst.append(element)
C. lst.insert(-1, element)
D. lst.extend(element)
PFP191 Multiple Choice Questions
PFP191_SU26_RE_948748 | Multiple Choice
Question 41
(Choose 1 answer)
Which of the following statements removes items 2 to 4 from a list?
A. del list[2:5]
B. del list[2:4]
C. list.remove(2, 4)
D. list.delete(2, 4)
PFP191_SU26_RE_948748 | Multiple Choice
Question 42
(Choose 1 answer)
Which of the following is the correct way to declare a variable in Python?
A. variableName = 10
B. 10 = variableName
C. variableName := 10
D. variableName == 10
PFP191_SU26_RE_948748 | Multiple Choice
Question 43
(Choose 1 answer)
What is the output of the following snippet code?
num1 = 4
num2 = 2
num3 = 3
result = num1 + num2 * num3 / (num2 - num1) ** 2
print(result)
A. 5.5
B. 5.0
C. 5.1
D. 5.2
PFP191_SU26_RE_948748 | Multiple Choice
Question 44
(Choose 2 answers)
Which of the following variable names are invalid?
A. _
B. _0
C. 0_
D. _0_
E. for_
F. for
PFP191_SU26_RE_948748 | Multiple Choice
Question 45
(Choose 1 answer)
How can you handle errors in user input in Python?
A. Using the try-except statement
B. Using the if-else statement
C. Using the for loop
D. Using the while loop
PFP191 SU26 Final Exam Multiple Choice Questions 46 to 50
PFP191_SU26_RE_948748 | Multiple Choice
Question 46
(Choose 1 answer)
What will be the value of x after the following statement executes:
x = 1 + 2 * 3 - 8 / 4
A. 3.0
B. 15
C. 4
D. 5.0
PFP191_SU26_RE_948748 | Multiple Choice
Question 47
(Choose 1 answer)
Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do?
x = x + 2
A. This would fail as it is a syntax error
B. Produce the value "false" because "x" can never equal "x+2"
C. Create a function called "x" and put the value 2 in the function
D. Retrieve the current value for x, add two to it and put the sum back into x
PFP191_SU26_RE_948748 | Multiple Choice
Question 48
(Choose 1 answer)
What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false?
A. otherwise
B. iterate
C. else
D. toggle
PFP191_SU26_RE_948748 | Multiple Choice
Question 49
(Choose 1 answer)
Which of the following statements is NOT true about the "or" operator in Python?
A. The "or" operator always evaluates all of its operands, regardless of their values
B. The "or" operator returns True if at least one of the operands is True
C. The "or" operator evaluates the operands from left to right
D. The "or" operator can be used to combine multiple conditions in a conditional statement
PFP191_SU26_RE_948748 | Multiple Choice
Question 50
(Choose 1 answer)
What is the output of the following Python code:
a = [1, 2, 3]
if len(a) != 3 and a[3] == 3:
print(a[3]
else:
print(a[0]
A. 1
B. IndexError: list index out of range
C. 2
D. 3
Đính kèm
-
PFP191 SU26 FE RE_001.webp53.9 KB · Lượt xem: 9 -
PFP191 SU26 FE RE_002.webp44.4 KB · Lượt xem: 11 -
PFP191 SU26 FE RE_003.webp39.6 KB · Lượt xem: 9 -
PFP191 SU26 FE RE_004.webp68.1 KB · Lượt xem: 7 -
PFP191 SU26 FE RE_005.webp41 KB · Lượt xem: 10 -
PFP191 SU26 FE RE_006.webp42.1 KB · Lượt xem: 9 -
PFP191 SU26 FE RE_007.webp40.1 KB · Lượt xem: 6 -
PFP191 SU26 FE RE_008.webp33.8 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_009.webp30.8 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_010.webp41.8 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_011.webp36.7 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_012.webp32.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_013.webp43.2 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_014.webp39.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_015.webp36.7 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_016.webp48.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_017.webp51.1 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_018.webp34.9 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_019.webp54.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_020.webp33 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_021.webp47.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_022.webp31.5 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_023.webp49.9 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_024.webp41.7 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_025.webp40.5 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_026.webp34.3 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_027.webp35.5 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_028.webp34.5 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_029.webp34.3 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_030.webp30.8 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_031.webp40.1 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_032.webp36.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_033.webp57.9 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_034.webp49.4 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_035.webp50 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_036.webp60.6 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_037.webp41 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_038.webp46.2 KB · Lượt xem: 5 -
PFP191 SU26 FE RE_039.webp34.8 KB · Lượt xem: 5 -
PFP191 SU26 FE RE_040.webp36.2 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_041.webp34.8 KB · Lượt xem: 5 -
PFP191 SU26 FE RE_042.webp37 KB · Lượt xem: 5 -
PFP191 SU26 FE RE_043.webp37.4 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_044.webp30.2 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_045.webp37.1 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_046.webp31.9 KB · Lượt xem: 4 -
PFP191 SU26 FE RE_047.webp55.7 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_048.webp40.1 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_049.webp57.2 KB · Lượt xem: 3 -
PFP191 SU26 FE RE_050.webp38.3 KB · Lượt xem: 11


