Font size
WorksheetsPython Programming Quiz
Total questions: 108
Worksheet time: 1hrs 4mins
Chọn câu sai:
Python cung cấp nhiều hàm tích hợp sẵn cho các tác vụ khác nhau mà người dùng có thể tự do sử dụng khi viết chương trình với lệnh gọi hàm tương ứng.
Một số hàm tích hợp sẵn của Python bao gồm: abs(), len(), range(), bool(), float(), print(), ...
Lệnh type(y) trả về kiểu dữ liệu của biến y.
Các hàm trong Python được định nghĩa bằng từ khóa del, theo sau là tên hàm.
Chọn câu sai:
Lệnh print() xuất ra màn hình.
Lệnh input() yêu cầu nhập một biểu thức hoặc số.
Lệnh type() trả về kiểu dữ liệu của biểu thức trong dấu ngoặc.
Lệnh str() chuyển đổi đối tượng đã cho thành chuỗi.
Chọn câu đúng:
Hàm float() trả về một số nguyên từ một biểu thức số hoặc chuỗi.
Có rất ít hàm tích hợp sẵn trong Python.
Hàm bool() chuyển đổi một giá trị thành Boolean.
Hàm input() có thể nhập một số nguyên mà không cần chuyển đổi kiểu.
Chọn câu sai:
Cú pháp để định nghĩa một hàm trả về giá trị: def
Cú pháp để định nghĩa một hàm không trả về giá trị: def
Một hàm phải có tham số và trả về giá trị sau từ khóa return.
Khối mã mô tả hàm được viết sau ':' và thụt vào.
Có bao nhiêu câu đúng trong các câu sau:
1) Python cung cấp nhiều hàm tích hợp sẵn cho các tác vụ khác nhau mà người dùng có thể tự do sử dụng.
2) Lệnh float() chuyển đổi đối tượng đã cho thành một số thực.
3) Lệnh int trả về một số nguyên từ một biểu thức số hoặc chuỗi.
4) Trong Python, người dùng chỉ có thể sử dụng các hàm tích hợp sẵn.
5) Người dùng có thể tạo thêm các hàm mới.
Chức năng của hàm sau đây là gì?
def sum(a, b): print("tổng = " + str(a + b))
Trả về tổng của hai số a và b được truyền vào.
Trả về hai giá trị a và b.
Tính tổng của hai số a và b.
Tính tổng của hai số a và b và hiển thị nó trên màn hình.
Chương trình sau có lỗi ở dòng nào?
Chương trình có bao nhiêu dòng mã có lỗi?
1.
2.
3.
4.
Kết quả của chương trình sau là gì?
5.
số thực.
số nguyên.
Chương trình có lỗi.
Kết quả của chương trình sau là gì?
5.
10.
50.
Chương trình có lỗi.
Kết quả của chương trình sau là gì?
3, 5, 9.
9, 15, 27.
9, 5, 27.
Chương trình có lỗi.
Khi chạy chương trình, nếu bạn nhập 'Hồ Hiếu Học', kết quả sẽ là gì?
Xin chào Hồ Hiếu Học
Hồ Hiếu Học
Xin chào em Hồ Hiếu Học
Xin chào ten
Nhận định nào là không chính xác?
str(): tham số là các kiểu dữ liệu khác nhau và trả về một chuỗi.
len(): tham số là một danh sách hoặc chuỗi và trả về một số thực.
float(): tham số là một chuỗi hoặc số nguyên và trả về một số thực.
len(): tham số là một danh sách hoặc chuỗi và trả về một số nguyên.
What is the syntax for defining a function that returns a value?
Trong số các lệnh sau, lệnh nào không phải là lệnh trong Python?
type
Read
input
What is the syntax for defining a function that does not return a value?
Which statement is incorrect?
A function can have or not have parameters.
The block of statements describing the function is written after the ':' and indented.
Functions in Python are defined by the keyword 'def', followed by the function name.
The block of statements describing the function is written after the ':' and does not need to be indented.
Which of the following statements is false?
The command x = int('52 + 25') converts the string '52 + 25' to the integer 77
The command x = int('52') converts the string '52' to the integer 52
The command type(y) returns the data type of variable y
The command print('Thời khoá biểu') prints the string 'Thời khoá biểu' to the screen
Các dòng mã sau đây tạo ra kết quả:
def thong_bao(msg): print('Xin chào bạn', msg) return thong_bao('Trần Quang Minh:)
Trần Quang Minh
Xin chao ban Trần Quang Minh
Xin chào bạn Trần Quang Minh
Xin chào bạn
Cú pháp chung để gọi một hàm trong Python là gì?
Các dòng mã sau đây tạo ra kết quả:
def inc(n): return n+1 inc(3)
3
5
6
4
Kết quả của đoạn mã sau là gì?
Không có gì xảy ra.
Lỗi do thiếu tham số.
6
3
Có bao nhiêu tham số mà một hàm trong Python có thể có?
Tối đa ba tham số.
Tối đa hai tham số.
Tối đa một tham số.
Nhiều tham số.
Kết quả của đoạn mã sau là gì?
Lỗi do thiếu lệnh in
Không có gì xảy ra.
3 + 5
8
Trong Python, từ khóa nào được sử dụng để định nghĩa một hàm?
func
def
Function
Define
Chỉ lệnh nào được sử dụng để gọi một hàm trong Python?
gọi function_name()
function_name()
chạy function_name()
thực thi function_name()
Kết quả của đoạn mã sau là gì?
"Xin chào, thế giới!"
Không có gì xảy ra.
Lỗi do thiếu return
say_hello()
Nếu một hàm không có câu lệnh trả về, giá trị trả về của nó là gì?
Không có
Lỗi chương trình.
Sai
0
Trong Python, tham số và đối số khác nhau như thế nào?
Trong Python, tham số và đối số khác nhau như thế nào?
Tham số là các biến được khai báo trong một hàm, đối số là các giá trị thực tế được truyền khi gọi hàm.
Python không phân biệt giữa tham số và đối số.
Tham số là các giá trị được truyền cho một hàm khi được gọi, đối số là các biến được khai báo trong hàm.
Tham số và đối số hoàn toàn giống nhau.
Có bao nhiêu tham số mà một hàm do người dùng định nghĩa trong Python có thể có?
0
1
2
Không giới hạn
Khi gọi một hàm, dữ liệu được truyền vào hàm được gọi là gì?
Tham số
Khác biệt
Đối số
Số hàm
Hàm func(m, n) được định nghĩa như sau: def func (m, n) : return 3*m + n Giả sử chúng ta thực hiện các lệnh sau: >>> m = 10 >>> n = 1 >>> print(func(n, m)) Kết quả sẽ in ra gì?
12
13
14
11
Số nào sẽ được chương trình sau in ra? >>>def f (x, y): z = x + y return x*y*z >>> f (1, 4):
10
18
20
30
Which statement is false?
A function declared with one parameter can be called with two arguments.
Parameters are defined when declaring a function.
Parameters and arguments have some differences.
When calling a function, parameters are passed by value through the function's arguments.
Giả sử hàm f có hai tham số khi được khai báo. Hai giá trị đối số nào được truyền vào sẽ gây ra lỗi?
2, 3.
10, c.
"a", "b".
"a", "3".
Khi gọi f(1, 2, 3), có bao nhiêu tham số được định nghĩa trong hàm f?
1.
2.
3.
4.
Kiểu dữ liệu của các tham số của hàm f nếu hàm f được gọi như sau: f( '5.0')
str
float.
int.
Không xác định.
Giá trị của m sau khi biết kết quả là 5: def tinhSum(a, b): return a + b s = tinhSum(1, m) print(s)
1.
4.
2.
3.
Giá trị của x sau khi biết kết quả là 8: def tinh(a, b, c): if (b != 0): return a // b + c*2 s = tinh(1, 5, x) print(s)
3.
2.
1.
4.
Định nghĩa hàm change() với hai tham số: ho_ten kiểu chuỗi và số c. Hàm sẽ trả về chuỗi ho_ten dưới dạng ch
Đầu ra của đoạn mã sau sẽ là gì? if (b != 0): return a // b + c*2 s = tinh(1, 5, x) print(s)
3
2
1
4
Định nghĩa hàm change() với hai tham số: ho_ten và c. Hàm sẽ trả về chuỗi ho_ten ở dạng chữ hoa nếu c = 0. Nếu c khác 0, nó sẽ trả về ho_ten ở dạng chữ thường. Khi chạy chương trình, nếu đầu vào là 'Nguyễn Lê Minh Anh' và c = 0, kết quả sẽ là gì?
Nguyễn Lê Minh Anh
Nguyễn lê minh anh
NGUYỄN LÊ MINH ANH
nguyễn lê minh anh
Đầu ra của chương trình sau sẽ là gì? def tongam(A): s=0 for k in A: if k<0: s = s + k return s A = [1,-2,4,-3,5,-1] tongam(A) print(tongam(A))
-10
6
-6
-16
Định nghĩa hàm power(a,b,c) trong đó a, b, c là các số nguyên. Hàm trả về giá trị của (a+b)^c. Khi chạy chương trình, nếu a=1, b=2, c=3, kết quả sẽ là gì?
6
9
27
16
Đầu ra của đoạn mã sau sẽ là gì? def f(a,b,c): return a+b+c x,y,z =10, 20, 30 f(x,y,z)
30
60
20
10
Trong chương trình sau, câu lệnh nào là đúng? def f_sum(a,b,c): return a+b+c x, y = 5, 3 f_sum(10,x,y)
(a,b,c) và (x,y) đều là đối số
(a,b,c) là một đối số, (x,y) là một tham số
(a,b,c) và (x,y) đều là tham số
(a,b,c) là một tham số, (x,y) là một đối số
Kết quả của đoạn mã sau sẽ là gì? def f(a, b, c): return a+b+c f(1,2,3)
1
6
3
2
Viết một chương trình nhận hai số tự nhiên từ bàn phím, cách nhau bởi một khoảng trắng. Tính và in ra tổng của hai số này. Chương trình có thể như sau: def tinhTong(A): t = 0 for i in range (0,len(A)): t = t + int(A[i]) return t s = input('Nhập 2 số cách nhau bởi dấu cách:') A = s.split(' ') print(tinhTong(A)). Nếu đầu vào là '5 6', kết quả sẽ là gì?
11
1
56
65
What statement is made?
Which statement is false?
Khi gọi một hàm, các tham số được truyền theo giá trị thông qua các đối số của hàm, số lượng giá trị được truyền vào hàm khác với số lượng tham số trong khai báo hàm.
Khi gọi một hàm, các tham số được truyền theo giá trị thông qua các đối số của hàm, số lượng giá trị được truyền vào hàm bằng với số lượng tham số trong khai báo hàm.
Các đối số là các giá trị được truyền khi gọi một hàm.
Các tham số hàm được định nghĩa khi khai báo hàm và được sử dụng như các biến trong định nghĩa hàm.
Chương trình sau đây cho kết quả:
11
16
10
15
In Python, a variable declared and used inside a function is called what?
Local variable
Private variable
Global variable
Common variable
Which statement below is false about the scope of variables in Python?
A variable declared inside a function only has effect within that function, and has no effect outside.
A variable declared outside a function will not have effect inside the function as a variable.
A variable declared outside will need to be redeclared inside the function with the global keyword to have effect inside.
A variable in Python, once declared, will have effect in all functions and outside.
Complete (…) in the following statement: "In Python, all variables declared inside a function are …, not effective outside … the function."
local, in.
local, out.
global, out.
global, in.
The number of true statements in the following statements is:
1)
2)
3)
0.
Choose the incorrect statement from the following statements:
The main program can use local variables inside the function.
Variables inside the function can have the same name as variables declared outside the function.
All variables in the function are local.
Variables inside the function are not effective outside the function.
What are the values of x, y when executing the command f(1, 3)?
2, 3.
4, 5.
5, 4.
3, 4.
What are the values of a, b when executing the command f(2, 5)?
10, 2.
10, 1.
2, 5.
0, 1.
What is the result of this program?
"I am named: Long".
"Long".
"I am named: ".
The program has an error.
What is the result of the following program?
"Today I went to school ".
"Hello World".
"Hello World!!!".
The program has an error.
What is the result of the following program?
5.
6.
11.
The program has an error.
Write a function with input as a list A containing numbers and a real number x. The function returns a result list B from list A by keeping only the elements greater than or equal to x. Which of the following programs is correct?
If an external variable wants to have an effect inside the function, which keyword should be used to declare?
input
len
global
def
Which statement is incorrect?
Variables declared inside a function can be used by the main program.
In Python, all variables declared outside a function are local.
Which statement is incorrect?
Variables declared inside a function can be used by the main program.
In Python, all variables declared inside a function are local and not effective outside the function.
A variable declared outside a function can only access its value inside the function without changing that variable's value (except with the global keyword).
Variables declared inside a function can only be used within that function. The main program cannot use them.
In Python, a variable declared and used inside a function is called what?
Local variable
Basic variable
Private variable
Global variable
Identify the type of error in the following statement: >>> A = list(12)
Syntax error
Runtime error
Other error
No error
Does the following statement have an error? If so, what type of error is it? 123ab = {1,2,3}
Syntax error
Runtime error
Other error
No error
What is a runtime error in Python?
An error when writing a statement with incorrect syntax of the programming language
An error when accessing a variable that has not been declared
An error when a command of the program cannot be executed
An error when the program compiles to an exe file.
What type of error does the following program have? A = [1, 2, 3] for i in range(4): print(A[i])
Syntax error
Other error
Semantic error
Runtime error
What type of error does the following program have? n = 10 for i in range(n): print(i, end=" ")
Syntax error
Other error
Semantic error
Runtime error
What type of error does the following program have? n = input("Enter a natural number n: ") k = int(input("Enter the number of times to multiply: ") print("The result is:", n*k)
Syntax error
Other error
Semantic error
Runtime error
In a function call, if the arguments passed to the function are missing, what type of runtime error occurs?
SyntaxError
NameError
TypeError
No runtime error occurs
What type of exception occurs if the arguments passed to the function are missing?
SyntaxError.
NameError.
TypeError.
No exception occurs.
What exception will the following commands raise? >>> s = abc >>> s[10]
SyntaxError.
NameError.
TypeError.
IndexError.
Assuming the program has the following exception input command: n = int(input("Enter an integer n:")) When we enter 1.5, what exception does the program raise?
SyntaxError.
ValueError
TypeError.
IndexError.
What error can line 3 raise? 1. n = int (input("Enter an integer n:")) 2. if prime (n): 3. print (n, "is a prime number") 4. else: 5. print (n, "is a composite number")
ValueError
TypeError.
NameError.
SyntaxError.
Which statement is false? A. The program runs without exceptions, but the result is incorrect. This is a logic error within the program. B. An error occurs when there is a command written with incorrect syntax or incorrect structure according to Python's language rules. The program will immediately stop and report a Syntax Error. C. The program runs without exceptions, but the result is incorrect. This is a syntax error within the program. D. An error occurs when a command in the program is not executed. The program stops and reports an error code. This error is called an exception (Exceptions Error), the returned error code is called an exception error code.
The program runs without exceptions, but the result is incorrect. This is a logic error within the program.
An error occurs when there is a command written with incorrect syntax or incorrect structure according to Python's language rules. The program will immediately stop and report a Syntax Error.
The program runs without exceptions, but the result is incorrect. This is a syntax error within the program.
An error occurs when a command in the program is not executed. The program stops and reports an error code. This error is called an exception (Exceptions Error), the returned error code is called an exception error code.
What is the exception error code of the command int("abc")?
TypeError
ValueError
NameError
SyntaxError
Which of the following answers is the most correct? Some exception error codes in Python are:
IndexError, NameError, TypeError, ValueError, IndentationError, SyntaxError
ZeroDivisionError, IndexError, NameError, TypeError
NameError, TypeError, ValueError, IndentationError, SyntaxError
ZeroDivisionError, IndexError, NameError, TypeError, ValueError, IndentationError, SyntaxError
The program reports a SyntaxError. What is this error?
Syntax error
Data type error
Value-related error
The program reports a SyntaxError. What is this error?
Syntax error
Data type error
Value-related error
Indentation error
How many types of program errors can be distinguished in Python?
4
1
3
2
The problem requires sorting the initial array into ascending order. Assuming the initial array is [3, 1, 8, 10, 0]. The result obtained is the array [1, 3, 8, 10, 0]. Does the program have an error?
Logic error
No error
Syntax error
Runtime error
Given the following program: n = input("Enter n:") A = [1,3,5,10,0] for i in range(0,n): print(A[i], end=" ") When running the program, if n = 5 is entered, the result is:
1 3 5 10 0
The program reports a TypeError
The program reports a NameError
Among the following programs, which program generates a TypeError?
A.
B.
C.
D.
What is the error code of the following program? A = [1,3,5,10,0] for k in range(1, len(A)): print(A[i], end=" ")
1 3 5 10 0
TypeError
NameError
3 5 10 0
The program reports a ZeroDivisionError, when does this occur?
This error occurs when dividing by 0.
This error occurs when the program tries to find a name but cannot.
This error occurs when trying to access an element of a list but the index exceeds the limit.
This error occurs when the lines of code are not indented correctly.
What is a logic error?
An error that occurs when calling an undeclared variable.
An error that occurs when the program runs incorrectly but does not report an error.
An error that occurs due to incorrect syntax.
An error that occurs when the program cannot run.
When does a TypeError occur?
When calling an undeclared variable.
When dividing a number by 0.
When accessing an empty list.
When using the wrong data type.
What is the result of the following code? x = 10/0 print(x)
0
ZeroDivisionError.
NameError.
What is the result of the following code? x = 10/0 print (x)
0
ZeroDivisionError
NameError
10
What is the result of the following code? x = "5" y = 2 print (x+y)
7
NameError
"52"
TypeError
What happens when the program has a syntax error?
The program runs but the result is wrong.
The program ignores the error and continues executing.
The program stops immediately and reports an error.
The program runs slower than usual.
In which case does a NameError usually occur?
When dividing a number by 0.
When calling a variable that has not been declared.
When accessing an element that is not in the list.
When there is a syntax error.
What is the result of the following code? list = [1,2,3,4] print (list[5])
IndexError
5
1
NameError
What error occurs when writing incorrect syntax in Python?
SyntaxError
Logic error
RuntimeError
Data type error
Complete the following statement: "There are many tools and methods to test programs. The tools aim to ... of the program and ..., ... errors that arise in the future"
Find errors, prevent, stop.
Find errors, prevent, handle.
Prevent, stop, handle errors.
Handle errors, prevent, stop.
Which of the following is not a tool for testing programs?
Intermediate variable printing tool.
Test data set generation tool.
Data statistics tool.
Breakpoint tool in programming software.
Which statement is most accurate when talking about test data sets in program testing?
Test sets can have inputs according to different criteria.
Test sets have inputs according to certain criteria.
Test sets can have inputs according to different criteria such as size, data diversity.
Test sets must have inputs according to criteria about size, data diversity.
Chương trình chạy phát sinh lỗi ngoại lệ ZeroDivision, nên xử lí như thế nào?
Kiểm tra lại giá trị số chia.
Kiểm tra lại chỉ số trong mảng.
Kiểm tra giá trị của số bị chia.
Kiểm tra kiểu dữ liệu nhập vào.
Trong các phát biểu sau, phát biểu nào chưa chính xác về kiểm thử chương trình?
Hiện nay, có ít phương pháp và công cụ khác nhau để kiểm thử chương trình.
Chương trình cần được thử với một số bộ dữ liệu test gồm đầu vào tiêu biểu và kết quả đầu ra biết trước.
Các bộ test phụ thuộc vào các tiêu chí khác nhau.
Các bộ test dữ liệu nên có nhiều bộ test ngẫu nhiên,...
Chương trình sau phát sinh lỗi gì?
NameError.
TypeError.
ZeroDivisionError.
Syntax Error.
Chương trình chạy phát sinh lỗi ngoại lệ IndexError, nên xử lí như thế nào?
Kiểm tra lại giá trị số chia.
Kiểm tra lại chỉ số trong mảng.
Kiểm tra giá trị của số bị chia.
Kiểm tra kiểu dữ liệu nhập vào.
Chương trình sau có lỗi ở dòng lệnh nào?
1.
2.
3.
4.
Chương trình chạy phát sinh lỗi ngoại lệ TypeError, nên xử lí như thế nào?
Kiểm tra lại chỉ số trong mảng.
Kiểm tra lại giá trị số chia.
Kiểm tra giá trị của số bị chia.
Kiểm tra kiểu dữ liệu nhập vào.
Chương trình chạy phát sinh lỗi ngoại lệ NameError, nên xử lí như thế nào?
Kiểm tra lại chỉ số trong mảng.
Kiểm tra lại tên các biến và hàm.
Kiểm tra giá trị của số bị chia.
Kiểm tra kiểu dữ liệu nhập vào.
