- Học kỳ
- SP2026
- Thời Gian
- 3/5/26
- Loại tài liệu
- FE
PFP191 SP26 B5 FE RE
Câu 1: Choose 1 answer Multiple Choice
Python
<span><span>class</span> <span>Dog</span>:</span><br> <span><span>def</span> <span>__init__</span>(<span>self, name, age</span>):</span><br> self.name = name<br> self.age = age<br>
The correct way to instantiate the above Dog class is:
Câu 2: Choose 1 answer Multiple Choice
- A. Dog()
- B. Dog("Rufus", 3)
- C. Dog.create("Rufus", 3)
- D. Dog__init__("Rufus", 3)
Đáp án: B
Which of the following is rarely used in Object Oriented Programming?
Câu 3: Choose 1 answer Multiple Choice
- A. Method
- B. Constructor
- C. Attribute
- D. Destructor
Đáp án: D
Which of the following statements is true about classes?
Câu 4: Choose 1 answer Multiple Choice
- A. Classes cannot inherit from other classes.
- B. Classes can contain both attributes and methods.
- C. Every class must have at least one attribute.
- D. Classes cannot create instances.
Đáp án: B
What is the result of this code?
Python
<span><span>class</span> <span>A</span>:</span><br> <span><span>def</span> <span>show</span>(<span>self</span>):</span><br> print(<span>"A"</span>)<br><span><span>class</span> <span>B</span>(<span>A</span>):</span><br> <span>pass</span><br><span><span>class</span> <span>C</span>(<span>B</span>):</span><br> <span>pass</span><br>obj = C()<br>obj.show()<br>
Câu 5: Choose 1 answer Multiple Choice
- A. "A"
- B. "B"
- C. "C"
- D. Error
Đáp án: A
In Python, a function within a class definition is called a:
Câu 6: Choose 1 answer Multiple Choice
- A. a method
- B. a class function
- C. an operation
- D. a factory
Đáp án: A
What does the @property decorator do in Python?
Câu 7: Choose 1 answer Multiple Choice
- A. Converts a function into a read-only attribute
- B. Hides a method from the user
- C. Makes a function private
- D. Creates a new class
Đáp án: A
What will be the output of this code?
Python
<span><span>class</span> <span>A</span>:</span><br> <span><span>def</span> <span>__init__</span>(<span>self</span>):</span><br> print(<span>"A constructor"</span>)<br><span><span>class</span> <span>B</span>(<span>A</span>):</span><br> <span><span>def</span> <span>__init__</span>(<span>self</span>):</span><br> print(<span>"B constructor"</span>)<br>obj = B()<br>
Câu 8: Choose 1 answer Multiple Choice
- A. A constructor
- B. B constructor
- C. A constructor B constructor
- D. Error
Đáp án: B
What will be the output of this code?
Python
<span><span>class</span> <span>Student</span>:</span><br> <span><span>def</span> <span>__init__</span>(<span>self, name</span>):</span><br> self.name = name<br>s = Student(<span>"Alice"</span>)<br>print(s.name)<br>
Câu 9: Choose 1 answer Multiple Choice
- A. Alice
- B. Error
- C. None
- D. s.name
Đáp án: A
In Object Oriented Programming, what is another name for the "attributes" of an object?
Câu 10: Choose 1 answer Multiple Choice
- A. forms
- B. methods
- C. portions
- D. messages
- E. fields
Đáp án: E
What is the output of the following snippet code?
Python
sentence = <span>"This-is;a-test"</span><br>words = sentence.split(<span>'-;'</span>)<br>print(words)<br>
Câu 11: Choose 1 answer Multiple Choice
- A. ['This-is;a-test']
- B. ['This' 'is' 'a' 'test']
- C. This, is, a, test
- D. This is a test
Đáp án: A
What will be the output of the following code?
Python
s = <span>"abracadabra"</span><br>print(s.rindex(<span>"a"</span>))<br>
Câu 12: Choose 1 answer Multiple Choice
- A. 10
- B. 3
- C. 5
- D. 0
Đáp án: A
What is the result of 'abcde'.find('c')?
Câu 13: Choose 1 answer Multiple Choice
- A. 1
- B. 2
- C. 3
- D. -1
Đáp án: B
Python strings have a property called "immutability." What does this mean?
Câu 14: Choose 1 answer Multiple Choice
- A. Strings can't be divided by numbers
- B. Strings in Python can't be changed
- C. Strings in Python can be represented as arrays of chars
- D. You can update a string in Python with concatenation
Đáp án: B
Which method removes all whitespace from the beginning and end of a string?
Câu 15: Choose 1 answer Multiple Choice
- A. strip()
- B. trim()
- C. clean()
- D. remove()
Đáp án: A
How can you efficiently check and count each word from a file without causing a KeyError if the word is not already in the dictionary?
Câu 16: Choose 1 answer Multiple Choice
- A. Use if-else to check presence of word
- B. Use dict[word] += 1 without checking
- C. Use dict.get(word, 0) + 1
- D. Use dict.setdefault(word, 0) + 1
Đáp án: C
What happens if you access a non-existing key in a dictionary using square brackets (dict[key])?
Câu 17: Choose 1 answer Multiple Choice
- A. Returns None
- B. Raises a KeyError
- C. Adds the key with None as its value
- D. Returns 0
Đáp án: B
What does the following Python code print out?
Python
a = [<span>1</span>, <span>2</span>, <span>3</span>, <span>8</span>]<br>b = [<span>4</span>, <span>5</span>, <span>6</span>]<br>c = a + b<br>print(c)<br>
Câu 18: Choose 1 answer Multiple Choice
- A. 28
- B. [1, 2, 3, 8, 4, 5, 6]
- C. It raises an exception
- D. 7
Đáp án: B
What does file.write("text") return?
Câu 19: Choose 1 answer Multiple Choice
- A. None
- B. The number of characters written
- C. The written string
- D. Raises an error
Đáp án: B
Which method in Python is used to read a single line from a text file?
Câu 20: Choose 1 answer Multiple Choice
- A. readline()
- B. read()
- C. readlines()
- D. getline()
Đáp án: A
What is stored in a "file handle" that is returned from a successful open() call?
Câu 21: Choose 1 answer Multiple Choice
- A. The handle is a connection to the file's data
- B. The handle contains the first 10 lines of a file
- C. All the data from the file is read into memory and stored in the handle
- D. The handle has a list of all of the files in a particular folder on the hard drive
Đáp án: A
The readlines() method returns...
Câu 22: Choose 1 answer Multiple Choice
- A. str
- B. a list of lines
- C. a list of single characters
- D. a list of integers
Đáp án: B
What is the last action that must be performed on a file?
Câu 23: Choose 1 answer Multiple Choice
- A. Close
- B. Save
- C. End
- D. Write
Đáp án: A
How does the 'open' function work in Python?
Câu 24: Choose 1 answer Multiple Choice
- A. It basically takes the name of a file as an argument and returns a file handle which can be used to perform operations on the file.
- B. It examines a program and analyses the syntactic structure.
- C. It iterates through the items in a sequence, performing a similar operation on each.
- D. It takes a format string and a tuple and generates a string that includes the elements of the tuple formatted as specified by the format string.
Đáp án: A
What does the code below mean? f = open("test.txt")
Câu 25: Choose 1 answer Multiple Choice
- A. Open the file test.txt with read and write permissions.
- B. Open the file test.txt with read-only permission.
- C. Open the file test.txt and allow overwriting the file.
- D. Open the file test.txt and allow appending to the file.
Đáp án: B
Which of the following CANNOT be variable names or identifiers in Python programming?
Câu 26: Choose 1 answer Multiple Choice
- A. while
- B. if
- C. and
- D. All of the above
Đáp án: D
What is a reserved word in Python?
Câu 27: Choose 1 answer Multiple Choice
- A. A word created by the programmer and assigned to a variable.
- B. A word that has one specific meaning to Python and cannot be used as a variable name.
- C. The name of a function available in Python.
- D. A slang term for especially well-written code.
Đáp án: B
Which of the following slicing operations will produce the list [12, 3]?
t = [9, 41, 12, 3, 74, 15]
Câu 28: Choose 1 answer Multiple Choice
- A. t[12:3]
- B. t[2:4]
- C. t[2:2]
- D. t[1:3]
Đáp án: B
Which of the parts of a computer actually executes the program instructions?
Câu 29: Choose 1 answer Multiple Choice
- A. RAM
- B. CPU
- C. Input/Output Devices
- D. Secondary Memory
Đáp án: B
What will happen if a string contains non-numeric characters and is converted using int()?
Câu 30: Choose 1 answer Multiple Choice
- A. It will return 0
- B. It will be converted to a float
- C. It will raise a ValueError
- D. It will be converted to a boolean
Đáp án: C
How can you use list comprehension to create a list of even numbers from 1 to 10?
Câu 31: Choose 1 answer Multiple Choice
- A. [x for x in range(1, 11) if x % 2 == 0]
- B. [2*x for x in range(1, 6)]
- C. [x*2 for x in range(10)]
- D. [x for x in range(1, 11) when x % 2 == 0]
Đáp án: A
What does the following Python code print out?
Python
a = [<span>1</span>, <span>2</span>, <span>3</span>]<br>b = [<span>4</span>, <span>5</span>, <span>6</span>]<br>c = a + b<br>print(<span>len</span>(c))<br>
Câu 32: Choose 1 answer Multiple Choice
- A. 21
- B. [4, 5, 6]
- C. 15
- D. 6
Đáp án: D
Which of the following methods does not exist for tuples?
Câu 33: Choose 1 answer Multiple Choice
- A. count()
- B. index()
- C. sort()
- D. len()
Đáp án: C
What is a function argument?
Câu 34: Choose 1 answer Multiple Choice
- A. A value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function.
- B. A way of calculating the result
- C. The result of a function
- D. A section of code that represents a command or action
Đáp án: A
Consider the following function in Python:
Python
<span><span>def</span> <span>func</span>(<span>n</span>):</span><br> <span>while</span> n > <span>0</span>:<br> print(n, end=<span>' '</span>)<br> n = n - <span>2</span><br>
What happens when the parameter n passed to the function is initially a positive odd number?
Câu 35: Choose 1 answer Multiple Choice
- A. The function will enter an infinite loop.
- B. The function will print numbers in reverse order until a negative number is reached.
- C. The function will print numbers in reverse order until 1 is reached.
- D. The function will not execute and return immediately.
Đáp án: A
What is the flow of execution in a program?
Câu 36: Choose 1 answer Multiple Choice
- A. The order in which statements are executed
- B. The sequence in which functions are defined
- C. The process of converting data types
- D. The way parameters are passed to functions
Đáp án: A
Which of the following reserved keyword is used to end a function, return generator?
Câu 37: Choose 1 answer Multiple Choice
- A. break
- B. switch
- C. Return
- D. yield
Đáp án: D
What is the output of the following code snippet?
Python
num = <span>4</span><br>result = <span>1</span><br><span>while</span> num > <span>1</span>:<br> result *= num<br> num -= <span>1</span><br>print(result)<br>
Câu 38: Choose 1 answer Multiple Choice
- A. 24
- B. 12
- C. 10
- D. 26
Đáp án: A
What is the extend() method used for?
Câu 39: Choose 1 answer Multiple Choice
- A. Adds an element to the end of a list.
- B. Concatenates two lists, adding all the elements of the given list to the current list.
- C. Replaces an element at a given position in the list.
- D. Returns a copy of the current list.
Đáp án: B
Which collection is ordered, changeable, and allows duplicate members?
Câu 40: Choose 1 answer Multiple Choice
- A. SET
- B. DICTIONARY
- C. TUPLE
- D. LIST
Đáp án: D
What is the result of:
Python
a = [<span>1</span>, <span>2</span>, <span>3</span>]<br>a[<span>0</span>:<span>2</span>] = [<span>5</span>]<br>print(a)<br>
Câu 41: Choose 1 answer Multiple Choice
- A. [5, 3]
- B. [1, 2, 5]
- C. [5, 2, 3]
- D. [1, 5, 3]
Đáp án: A
Which of the following elements of a mathematical expression in Python is evaluated last?
Câu 42: Choose 1 answer Multiple Choice
- A. Addition
- B. Multiplication
- C. Parentheses
- D. Division
Đáp án: A
In the following code, print(98.6). What is "98.6"?
Câu 43: Choose 1 answer Multiple Choice
- A. A conditional statement
- B. A constant
- C. An iteration / loop statement
- D. A variable
Đáp án: B
What is the primary function of the 'input' function in Python programs?
Câu 44: Choose 1 answer Multiple Choice
- A. To output data to the console
- B. To take user input as a string
- C. To display user inputs
- D. To define variables
Đáp án: B
What will be the output of the following code snippet?
print(23 + (5 + 6)(1 + 1))
Câu 45: Choose 1 answer Multiple Choice
- A. 129
- B. 8
- C. 121
- D. None of the above
Đáp án: A
What will be the output of the following code?
Python
x = <span>5</span><br>y = <span>10</span><br>print(x * y + x / y)<br>
Câu 46: Choose 1 answer Multiple Choice
- A. 50.5
- B. 55.5
- C. 50.1
- D. 51.0
Đáp án: A
What does the term "algorithm" mean in the context of programming?
Câu 47: Choose 1 answer Multiple Choice
- A. A high-level programming language
- B. A step-by-step procedure or formula for solving a problem
- C. A reserved keyword in Python
- D. The output of a program
Đáp án: B
Which of the following variable names are invalid?
Câu 48: Choose 1 answer Multiple Choice
- A. _
- B. 0
- C. 0_
- D. 0
- E. for_
- F. forĐáp án: C (Dựa trên hình ảnh có dấu tích ở C, nhưng thực tế cả B, C, D, F đều có vấn đề trong Python tùy ngữ cảnh; trong tài liệu chọn C)
Which of the following options correctly represents the precedence of the logical operators and, or, and NOT in Python, from highest to lowest?
Câu 49: Choose 1 answer Multiple Choice
- A. not, and, or
- B. or, and, not
- C. and, or, not
- D. not, or, and
Đáp án: A
Which logical operator is used to combine multiple conditions and returns True if all conditions are True?
Câu 50: Choose 1 answer Multiple Choice
- A. and
- B. or
- C. xor
- D. not
Đáp án: A
Assume we have the file.txt contains:
"for line in hand:
count = count + 1
print('Line Count:', count)"
What happens with the following code?
Python
f = <span>open</span>(<span>"file.txt"</span>)<br>print(<span>len</span>(f.readlines()))<br>
- A. 0
- B. 1
- C. 3
- D. Error
Đáp án: C
Đính kèm
-
PFP191 SP26 B5 FE RE_001.webp48.5 KB · Lượt xem: 4 -
PFP191 SP26 B5 FE RE_002.webp34.9 KB · Lượt xem: 4 -
PFP191 SP26 B5 FE RE_003.webp55.8 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_004.webp40 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_005.webp32.5 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_006.webp46 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_007.webp49.5 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_008.webp41.3 KB · Lượt xem: 1 -
PFP191 SP26 B5 FE RE_009.webp33.8 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_010.webp45.8 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_011.webp30.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_012.webp22.2 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_013.webp60.2 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_014.webp31.9 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_015.webp43.8 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_016.webp37.1 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_017.webp37.2 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_018.webp34 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_019.webp33.5 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_020.webp63.6 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_021.webp30.5 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_022.webp28.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_023.webp65.4 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_024.webp60 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_025.webp31.6 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_026.webp52.1 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_027.webp34.9 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_028.webp36.9 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_029.webp41.1 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_030.webp44 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_031.webp32.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_032.webp30.5 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_033.webp45.4 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_034.webp68 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_035.webp53.3 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_036.webp31.6 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_037.webp36.3 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_038.webp50.6 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_039.webp33.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_040.webp28 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_041.webp33.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_042.webp37.3 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_043.webp44.4 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_044.webp33.8 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_045.webp30.7 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_046.webp53.5 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_047.webp27 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_048.webp34.3 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_049.webp27 KB · Lượt xem: 0 -
PFP191 SP26 B5 FE RE_050.webp47 KB · Lượt xem: 4