Đề Thi FE PFP191 - SP26 - B5 - FE

adminadmin is verified member.

Member
Thành viên BQT
Administrator
Học kỳ
SP2026
Thời Gian
28/4/26
Loại tài liệu
FE
Mã Đề
PFP191_SP26_B5FE_482106
PFP191 SP26 B5 FE
Question 1 (Choose 1 answer) If you write a Python program to read a text file and you see extra blank lines in the output that are not present in the file input as shown below, what Python string function will likely solve the problem? From: [email protected] From: [email protected] From: [email protected] From: [email protected]
A. trim()
B. $file()$
C. startwith()
D. rstrip()
Question 2 (Choose 1 answer) What will be the result of Ist.pop() if the list Ist is empty?
A. Returns None B. Raises an IndexError C. Returns D. Removes the first element
Question 3 (Choose 1 answer) Suppose you are given a set(s1 $1=\{1,2,3\})$ then what is the output for the code 2* s1?
Α. (1,1,2,2,3,3)
Β. [1,1,2,2,3,3]
C. Illegal
D. (1,2,3,1,2,3)
Question 4 (Choose 1 answer) What would the following mean in a regular expression? [a-z0-9]
A. Match any number of lowercase letters followed by any number of digits
B. Match a lowercase letter or a digit
C. Match an entire line as long as it is lowercase letters or digits
D. Match any text that is surrounded by square braces
Question 5 (Choose 1 answer) How do you unpack a tuple into individual variables? A. var1, $var2=my$ my_tuple B. unpack(my_tuple, var1, var2) C. my_tuple.unpack(var1, var2) D. $var1=var2=my\_tuple$
Question 6 (Choose 1 answer) The isinstance() function is used to: A. Check if a variable is a class B. Check if an object is an instance of a specific class or a subclass thereof C. Check if an object has a specific method D. Check if a function is an instance method
Question 7 (Choose 1 answer) Which method is used to get elements according to a given index range in a List? A. slice() B. range() C. getitem() D. A and C are both correct
Question 8 (Choose 1 answer) Which of the following is not a Python reserved word? A. iterate B. continue C. else D. break
Question 9 (Choose 1 answer) Which one is NOT a legal variable name? A._myvar B. Myvar C. My_var D. My-var
Question 10 (Choose 1 answer) What will be the output of the following code? def foo(x): return $x^{*}2$ print(foo(3)) A. 6 B. 3 C. 9 D. 12
Question 11 (Choose 1 answer) Which OOP principle ensures that data is hidden from the user? A. Abstraction B. Polymorphism C. Encapsulation D. Inheritance
Question 12 (Choose 1 answer) When is the_init_ method executed? A. After creating an object B. Before an object is deleted C. As soon as the class is defined D. When an object is instantiated
Question 13 (Choose 1 answer) What does the following Python Program print out?str1 = "Hello" str2 = 'there'$bob=str1+str2$print(bob) A. Hello B. 0 C. Hellothere D. Hello there
Question 14 (Choose 1 answer) How do you define a private variable in a Python class? A. Prefix it with an underscore var B. Prefix it with two underscores_var C. Use the private keyword D. Use the protect keyword
Question 15 (Choose 1 answer) What will the below script print out?$s1=$ "rewrite" $s2=$ "your code" $s3=s1$ $s3=s3.replace(^{\prime\prime}r^{\prime\prime},"R^{\prime\prime},1)$$print(s1+^{\prime\prime\prime\prime\prime}+s3+^{\prime\prime\prime}+s2)$ A. RewRite RewRite your code B. Rewrite Rewrite your code C. rewrite Rewrite your code D. A TypeError will be raised.
Question 16 (Choose 2 answers) Which is the correct way to create a tuple? choose 02 answers. A. $my\_tuple=(1,2,3)$ B. $my\_tuple=[1,2,3]$ C. $my\_tuple=1,2,3$ D. $my\_tuple=\{1,2,3\}$
Question 17 (Choose 1 answer) What is the value of the following expression? 45% 10 A. 4 B. 2 C. 5 D. 0.42
Question 18 (Choose 1 answer) Which of the following commands can be used to read the next line in a file using the file object ? A. tmpfile.read(n) B. tmpfile.read() C. tmpfile.readline() D. tmpfile.readlines()
Question 19 (Choose 1 answer) What is the error in the following script?print('What is HungTN's phone number?"") A. LogicError B. RuntimeError C. SyntaxError D. SemanticError
Question 20 (Choose 1 answer) What will be the output of the following command:$print(r^{\prime\prime}lnhello^{\prime\prime})$ A. hello B. New line and hello C. \nhello D. Error
Question 21 (Choose 1 answer) What does the Central Processing Unit (CPU) do? A. Stores data for long-term use B. Connects the computer to the internet C. Executes instructions from software programs D. Outputs data to the display
Question 22 (Choose 1 answer) In Python, what is the purpose of the "continue" keyword? A. Skips the current iteration in a loop B. Terminates the program C. Declares a constant D. Imports a module
Question 23 (Choose 1 answer) What does the following code do? astr = 'Hello Bob' try: $istr=int(astr)$ except istr $=-1$ print('First', istr) astr $=^{\prime}123^{\prime}$ try:$istr=int(astr)$except istr $=-1$ print('Second', istr) A. Prints First-1 and Second 123 B. Prints First Hello Bob and Second 123 C. Error because 'Hello Bob' cannot be converted to an integer D. Prints First 0 and Second 123
Question 24 (Choose 1 answer) Which one is NOT a legal variable name? A. my-var B. Myvar C. my_var D._myvar
Question 25 (Choose 1 answer) The if-elif-else statement is used to: A. Perform different actions based on conditions B. Define functions C. Repeat a block of code D. All of A, B, and C are correct.
Question 26 (Choose 1 answer) How do you convert a list to a tuple? A. tuple(list) B. list.to_tuple() C. tuple from list(list) D. list(tuple)
Question 27 (Choose 1 answer) The following code sequence fails with a traceback when the user enters a file that does not exist. How would you avoid the traceback and make it so you could print out your own error message when a bad file name was entered? fname raw_input('Enter the file name: ') fhand = open(fname) A. try/except B. signal handlers C. try/catch/finally D. on error resume next
Question 28 (Choose 1 answer) Once again consider this dictionary:d = ('foo': 100, 'bar': 200, 'baz': 300)What is the result of this statement:d['bar': 'baz'] A. It raises an exception Β. 200 300 C. [200, 300] D. (200, 300)
Question 29 (Choose 1 answer) How are Python dictionaries different from Python lists? A. Python dictionaries are a collection and lists are not a collection B. Python lists are indexed using integers and dictionaries can use strings as indexes C. Python lists can store strings and dictionaries can only store words D. Python lists store multiple values and dictionaries store a single value
Question 30 (Choose 1 answer) What is the output of the following function call def funi (num): return num + 25 fun1 (5) print (num) A. 5 B. None of the mentioned C. NameError D. 25
Question 31 (Choose 1 answer) What will happen if you try to convert the string "abc" to an integer using the int() function? A. It will raise a ValueError B. It will return 0 C. It will return 1 D. It will return the string itself
Question 32 (Choose 1 answer) What is the output of the following code snippet?$nums=[3,1,8,7,9$]result = nums[0]for num in nums: if num > result: result = num print(result) A. 9 B. 8 C. 7 D. 1
Question 33 (Choose 1 answer) What does the following list comprehension do?squares = [x**2 for x in range(5)] A. Creates a list of numbers from 0 to 5 B. Creates a list of the squares of numbers from 0 to 4 C. Creates a list of the square roots of numbers from 0 to 4 D. Creates a list of the cubes of numbers from 0 to 5
Question 34 (Choose 1 answer) What does the following code snippet do?word = "example"for letter in word: print(letter) A. Prints each character in the word on a separate line. B. Reverses the characters in the word. C. Counts the occurrences of char in the word. D. Runtime Error.
Question 35 (Choose 1 answer) A list of lines is returned if using the method of ..... A. <readable()> B. <readnines()> C. <readlines()> D. <readline()>
Question 36 (Choose 1 answer) Which method is used to call a function? A. call my_function() B. my_function() C. execute my_function() D. run my_function()
Question 37 (Choose 1 answer) When a child class inherits from a parent class, the child class can: A. Only use the methods of the parent class and cannot change them B. Has all the attributes and methods of the parent class plus additional attributes and methods defined by the child class C. Only use the properties of the parent class and cannot add new properties D. Cannot access the properties and methods of the parent class
Question 38 (Choose 1 answer) What would the following Python code print out?stuff = dict() print(stuff['candy']) A. -1 B. 0 C. The program would fail with a traceback D. candy
Question 39 (Choose 1 answer) What is "code" in the context of this course? A. A password we use to unlock Python features B. A way to encrypt data during World War II C. A sequence of instructions in a programming language D. A set of rules that govern the style of programs
Question 40 (Choose 1 answer) What is the output of the following code? $x=0$ while $x<3$ print(x) $x+=1$ A. 0123 B. 012 C. 123 D. 12
Question 41 (Choose 2 answers) Given the file dog_breeds.txt, which of the following is the correct way to open the file for reading as a text file? A. open('dog_breeds.txt', 'rb') B. open('dog_breeds.txt', 'w') C. open('dog_breeds.txt', 'r') D. open('dog_breeds.txt') E. open('dog_breeds.txt', 'wb')
Question 42 (Choose 1 answer) Which character represents the List data type? A. (0) B. C. {} D. <>
Question 43 (Choose 1 answer) Given the following variable declarations in Python:message = "Hello, world!" $n=2024$ $pi=3.14159$ What are the data types of the variables message, n, and pi, respectively? A. str, int, float B. int, str, bool C. float, bool, str D. bool, float, int
Question 44 (Choose 1 answer) How can you iterate both keys and values in dictionary d? A. for k, v in d.items(): B. for k, v in d.item(): C. for k, v in d: D. for k, v in d.keys():
Question 45 (Choose 1 answer) Which of the following Python statements would print out the length of a list stored in the variable data? A. print(length(data)) B. print(data.length()) C. print(len(data)) D. print(data.length)
Question 46 (Choose 1 answer) What is the output of the following code:class MyClass: class_var = 'class variable' def_init__(self, instance_var): self.instance_var = instance_var obj1 MyClass(10) obj2 MyClass (20) MyClass.class_var = 'xxx' print(obj1.class_var, obj2.class_var) A. xxx xxx Β. 10 20 C. 20 10 D. class variable class variable
Question 47 (Choose 1 answer) What is the output of the following code? fruit = 'banana' print(fruit[1.5]) A. TypeError B. ValueError C. KeyError D. IndexErroг
Question 48 (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.
Question 49 (Choose 1 answer) What would the following Python code print out?stuff = dict() $print(stuff.get(^{\prime}candy^{\prime},-1))$ A. -1 B. The program would fail with a traceback C. 0 D. 'candy'
Question 50 (Choose 1 answer) What does the expression fruit[-1] return for fruit = 'banana'? A. b B. n C. a D. None
 

Đính kèm

  • PFP191 SP26 B5 PE_page-0001.webp
    PFP191 SP26 B5 PE_page-0001.webp
    191.8 KB · Lượt xem: 12
  • PFP191 SP26 B5 PE_page-0002.webp
    PFP191 SP26 B5 PE_page-0002.webp
    257.8 KB · Lượt xem: 11
  • PFP191 SP26 B5 PE_page-0003.webp
    PFP191 SP26 B5 PE_page-0003.webp
    208.5 KB · Lượt xem: 7
  • PFP191 SP26 B5 PE_page-0004.webp
    PFP191 SP26 B5 PE_page-0004.webp
    116.2 KB · Lượt xem: 5
  • PFP191 SP26 B5 PE_page-0005.webp
    PFP191 SP26 B5 PE_page-0005.webp
    167.8 KB · Lượt xem: 6
  • PFP191 SP26 B5 PE_page-0006.webp
    PFP191 SP26 B5 PE_page-0006.webp
    163.1 KB · Lượt xem: 5
  • PFP191 SP26 B5 PE_page-0007.webp
    PFP191 SP26 B5 PE_page-0007.webp
    174.9 KB · Lượt xem: 3
  • PFP191 SP26 B5 PE_page-0008.webp
    PFP191 SP26 B5 PE_page-0008.webp
    119.9 KB · Lượt xem: 4
  • PFP191 SP26 B5 PE_page-0009.webp
    PFP191 SP26 B5 PE_page-0009.webp
    152.2 KB · Lượt xem: 4
  • PFP191 SP26 B5 PE_page-0010.webp
    PFP191 SP26 B5 PE_page-0010.webp
    198.1 KB · Lượt xem: 4
  • PFP191 SP26 B5 PE_page-0011.webp
    PFP191 SP26 B5 PE_page-0011.webp
    148.7 KB · Lượt xem: 3
  • PFP191 SP26 B5 PE_page-0012.webp
    PFP191 SP26 B5 PE_page-0012.webp
    235 KB · Lượt xem: 3
  • PFP191 SP26 B5 PE_page-0013.webp
    PFP191 SP26 B5 PE_page-0013.webp
    288.5 KB · Lượt xem: 3
  • PFP191 SP26 B5 PE_page-0014.webp
    PFP191 SP26 B5 PE_page-0014.webp
    203.2 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0015.webp
    PFP191 SP26 B5 PE_page-0015.webp
    181.9 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0016.webp
    PFP191 SP26 B5 PE_page-0016.webp
    227.2 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0017.webp
    PFP191 SP26 B5 PE_page-0017.webp
    225.4 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0018.webp
    PFP191 SP26 B5 PE_page-0018.webp
    146.7 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0019.webp
    PFP191 SP26 B5 PE_page-0019.webp
    223 KB · Lượt xem: 2
  • PFP191 SP26 B5 PE_page-0020.webp
    PFP191 SP26 B5 PE_page-0020.webp
    239.2 KB · Lượt xem: 3
  • PFP191 SP26 B5 PE_page-0021.webp
    PFP191 SP26 B5 PE_page-0021.webp
    131.5 KB · Lượt xem: 12
Sửa lần cuối:

Tạo tài khoản hoặc đăng nhập để bình luận

Bạn phải là thành viên mới có thể bình luận.

Tạo tài khoản

Hãy tạo tài khoản trên cộng đồng của chúng tôi. Thật dễ dàng!

Đăng nhập

Bạn đã có tài khoản? Đăng nhập tại đây.

Back
Top