wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 108

Worksheet time: 1hrs 4mins

Name
Class
Date
1.

Chọn câu sai:

a)

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.

b)

Một số hàm tích hợp sẵn của Python bao gồm: abs(), len(), range(), bool(), float(), print(), ...

c)

Lệnh type(y) trả về kiểu dữ liệu của biến y.

d)

Các hàm trong Python được định nghĩa bằng từ khóa del, theo sau là tên hàm.

2.

Chọn câu sai:

a)

Lệnh print() xuất ra màn hình.

b)

Lệnh input() yêu cầu nhập một biểu thức hoặc số.

c)

Lệnh type() trả về kiểu dữ liệu của biểu thức trong dấu ngoặc.

d)

Lệnh str() chuyển đổi đối tượng đã cho thành chuỗi.

3.

Chọn câu đúng:

a)

Hàm float() trả về một số nguyên từ một biểu thức số hoặc chuỗi.

b)

Có rất ít hàm tích hợp sẵn trong Python.

c)

Hàm bool() chuyển đổi một giá trị thành Boolean.

d)

Hàm input() có thể nhập một số nguyên mà không cần chuyển đổi kiểu.

4.

Chọn câu sai:

a)

Cú pháp để định nghĩa một hàm trả về giá trị: def (): return

b)

Cú pháp để định nghĩa một hàm không trả về giá trị: def (): return

c)

Một hàm phải có tham số và trả về giá trị sau từ khóa return.

d)

Khối mã mô tả hàm được viết sau ':' và thụt vào.

5.

Có bao nhiêu câu đúng trong các câu sau:

a)

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.

b)

2) Lệnh float() chuyển đổi đối tượng đã cho thành một số thực.

c)

3) Lệnh int trả về một số nguyên từ một biểu thức số hoặc chuỗi.

d)

4) Trong Python, người dùng chỉ có thể sử dụng các hàm tích hợp sẵn.

e)

5) Người dùng có thể tạo thêm các hàm mới.

6.

Chức năng của hàm sau đây là gì?

a)

def sum(a, b): print("tổng = " + str(a + b))

b)

Trả về tổng của hai số a và b được truyền vào.

c)

Trả về hai giá trị a và b.

d)

Tính tổng của hai số a và b.

e)

Tính tổng của hai số a và b và hiển thị nó trên màn hình.

7.

Chương trình sau có lỗi ở dòng nào?

4 lines
8.

Chương trình có bao nhiêu dòng mã có lỗi?

a)

1.

b)

2.

c)

3.

d)

4.

9.

Kết quả của chương trình sau là gì?

a)

5.

b)

số thực.

c)

số nguyên.

d)

Chương trình có lỗi.

10.

Kết quả của chương trình sau là gì?

a)

5.

b)

10.

c)

50.

d)

Chương trình có lỗi.

11.

Kết quả của chương trình sau là gì?

a)

3, 5, 9.

b)

9, 15, 27.

c)

9, 5, 27.

d)

Chương trình có lỗi.

12.

Khi chạy chương trình, nếu bạn nhập 'Hồ Hiếu Học', kết quả sẽ là gì?

a)

Xin chào Hồ Hiếu Học

b)

Hồ Hiếu Học

c)

Xin chào em Hồ Hiếu Học

d)

Xin chào ten

13.

Nhận định nào là không chính xác?

a)

str(): tham số là các kiểu dữ liệu khác nhau và trả về một chuỗi.

b)

len(): tham số là một danh sách hoặc chuỗi và trả về một số thực.

c)

float(): tham số là một chuỗi hoặc số nguyên và trả về một số thực.

d)

len(): tham số là một danh sách hoặc chuỗi và trả về một số nguyên.

14.

What is the syntax for defining a function that returns a value?

a)
b)
c)
d)
15.

Trong số các lệnh sau, lệnh nào không phải là lệnh trong Python?

a)

type

b)

Read

c)

input

d)

print

16.

What is the syntax for defining a function that does not return a value?

a)
b)
c)
d)
17.

Which statement is incorrect?

a)

A function can have or not have parameters.

b)

The block of statements describing the function is written after the ':' and indented.

c)

Functions in Python are defined by the keyword 'def', followed by the function name.

d)

The block of statements describing the function is written after the ':' and does not need to be indented.

18.

Which of the following statements is false?

a)

The command x = int('52 + 25') converts the string '52 + 25' to the integer 77

b)

The command x = int('52') converts the string '52' to the integer 52

c)

The command type(y) returns the data type of variable y

d)

The command print('Thời khoá biểu') prints the string 'Thời khoá biểu' to the screen

19.

Các dòng mã sau đây tạo ra kết quả:

a)

def thong_bao(msg): print('Xin chào bạn', msg) return thong_bao('Trần Quang Minh:)

b)

Trần Quang Minh

c)

Xin chao ban Trần Quang Minh

d)

Xin chào bạn Trần Quang Minh

e)

Xin chào bạn

20.

Cú pháp chung để gọi một hàm trong Python là gì?

a)

= ()

b)

()

c)

: ()

21.

Các dòng mã sau đây tạo ra kết quả:

a)

def inc(n): return n+1 inc(3)

b)

3

c)

5

d)

6

e)

4

22.

Kết quả của đoạn mã sau là gì?

a)

Không có gì xảy ra.

b)

Lỗi do thiếu tham số.

c)

6

d)

3

23.

Có bao nhiêu tham số mà một hàm trong Python có thể có?

a)

Tối đa ba tham số.

b)

Tối đa hai tham số.

c)

Tối đa một tham số.

d)

Nhiều tham số.

24.

Kết quả của đoạn mã sau là gì?

a)

Lỗi do thiếu lệnh in

b)

Không có gì xảy ra.

c)

3 + 5

d)

8

25.

Trong Python, từ khóa nào được sử dụng để định nghĩa một hàm?

a)

func

b)

def

c)

Function

d)

Define

26.

Chỉ lệnh nào được sử dụng để gọi một hàm trong Python?

a)

gọi function_name()

b)

function_name()

c)

chạy function_name()

d)

thực thi function_name()

27.

Kết quả của đoạn mã sau là gì?

a)

"Xin chào, thế giới!"

b)

Không có gì xảy ra.

c)

Lỗi do thiếu return

d)

say_hello()

28.

Nếu một hàm không có câu lệnh trả về, giá trị trả về của nó là gì?

a)

Không có

b)

Lỗi chương trình.

c)

Sai

d)

0

29.

Trong Python, tham số và đối số khác nhau như thế nào?

4 lines
30.

Trong Python, tham số và đối số khác nhau như thế nào?

a)

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.

b)

Python không phân biệt giữa tham số và đối số.

c)

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.

d)

Tham số và đối số hoàn toàn giống nhau.

31.

Có bao nhiêu tham số mà một hàm do người dùng định nghĩa trong Python có thể có?

a)

0

b)

1

c)

2

d)

Không giới hạn

32.

Khi gọi một hàm, dữ liệu được truyền vào hàm được gọi là gì?

a)

Tham số

b)

Khác biệt

c)

Đối số

d)

Số hàm

33.

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ì?

a)

12

b)

13

c)

14

d)

11

34.

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):

a)

10

b)

18

c)

20

d)

30

35.

Which statement is false?

a)

A function declared with one parameter can be called with two arguments.

b)

Parameters are defined when declaring a function.

c)

Parameters and arguments have some differences.

d)

When calling a function, parameters are passed by value through the function's arguments.

36.

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?

a)

2, 3.

b)

10, c.

c)

"a", "b".

d)

"a", "3".

37.

Khi gọi f(1, 2, 3), có bao nhiêu tham số được định nghĩa trong hàm f?

a)

1.

b)

2.

c)

3.

d)

4.

38.

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')

a)

str

b)

float.

c)

int.

d)

Không xác định.

39.

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)

a)

1.

b)

4.

c)

2.

d)

3.

40.

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)

a)

3.

b)

2.

c)

1.

d)

4.

41.

Đị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

4 lines
42.

Đầ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)

a)

3

b)

2

c)

1

d)

4

43.

Đị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ì?

a)

Nguyễn Lê Minh Anh

b)

Nguyễn lê minh anh

c)

NGUYỄN LÊ MINH ANH

d)

nguyễn lê minh anh

44.

Đầ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))

a)

-10

b)

6

c)

-6

d)

-16

45.

Đị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ì?

a)

6

b)

9

c)

27

d)

16

46.

Đầ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)

a)

30

b)

60

c)

20

d)

10

47.

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)

(a,b,c) và (x,y) đều là đối số

b)

(a,b,c) là một đối số, (x,y) là một tham số

c)

(a,b,c) và (x,y) đều là tham số

d)

(a,b,c) là một tham số, (x,y) là một đối số

48.

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)

a)

1

b)

6

c)

3

d)

2

49.

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ì?

a)

11

b)

1

c)

56

d)

65

50.

What statement is made?

4 lines
51.

Which statement is false?

a)

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.

b)

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ác đối số là các giá trị được truyền khi gọi một hàm.

d)

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.

52.

Chương trình sau đây cho kết quả:

a)

11

b)

16

c)

10

d)

15

53.

In Python, a variable declared and used inside a function is called what?

a)

Local variable

b)

Private variable

c)

Global variable

d)

Common variable

54.

Which statement below is false about the scope of variables in Python?

a)

A variable declared inside a function only has effect within that function, and has no effect outside.

b)

A variable declared outside a function will not have effect inside the function as a variable.

c)

A variable declared outside will need to be redeclared inside the function with the global keyword to have effect inside.

d)

A variable in Python, once declared, will have effect in all functions and outside.

55.

Complete (…) in the following statement: "In Python, all variables declared inside a function are …, not effective outside … the function."

a)

local, in.

b)

local, out.

c)

global, out.

d)

global, in.

56.

The number of true statements in the following statements is:

a)

1)

b)

2)

c)

3)

d)

0.

57.

Choose the incorrect statement from the following statements:

a)

The main program can use local variables inside the function.

b)

Variables inside the function can have the same name as variables declared outside the function.

c)

All variables in the function are local.

d)

Variables inside the function are not effective outside the function.

58.

What are the values of x, y when executing the command f(1, 3)?

a)

2, 3.

b)

4, 5.

c)

5, 4.

d)

3, 4.

59.

What are the values of a, b when executing the command f(2, 5)?

a)

10, 2.

b)

10, 1.

c)

2, 5.

d)

0, 1.

60.

What is the result of this program?

a)

"I am named: Long".

b)

"Long".

c)

"I am named: ".

d)

The program has an error.

61.

What is the result of the following program?

a)

"Today I went to school ".

b)

"Hello World".

c)

"Hello World!!!".

d)

The program has an error.

62.

What is the result of the following program?

a)

5.

b)

6.

c)

11.

d)

The program has an error.

63.

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?

a)
b)
c)
d)
64.

If an external variable wants to have an effect inside the function, which keyword should be used to declare?

a)

input

b)

len

c)

global

d)

def

65.

Which statement is incorrect?

a)

Variables declared inside a function can be used by the main program.

b)

In Python, all variables declared outside a function are local.

66.

Which statement is incorrect?

a)

Variables declared inside a function can be used by the main program.

b)

In Python, all variables declared inside a function are local and not effective outside the function.

c)

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).

d)

Variables declared inside a function can only be used within that function. The main program cannot use them.

67.

In Python, a variable declared and used inside a function is called what?

a)

Local variable

b)

Basic variable

c)

Private variable

d)

Global variable

68.

Identify the type of error in the following statement: >>> A = list(12)

a)

Syntax error

b)

Runtime error

c)

Other error

d)

No error

69.

Does the following statement have an error? If so, what type of error is it? 123ab = {1,2,3}

a)

Syntax error

b)

Runtime error

c)

Other error

d)

No error

70.

What is a runtime error in Python?

a)

An error when writing a statement with incorrect syntax of the programming language

b)

An error when accessing a variable that has not been declared

c)

An error when a command of the program cannot be executed

d)

An error when the program compiles to an exe file.

71.

What type of error does the following program have? A = [1, 2, 3] for i in range(4): print(A[i])

a)

Syntax error

b)

Other error

c)

Semantic error

d)

Runtime error

72.

What type of error does the following program have? n = 10 for i in range(n): print(i, end=" ")

a)

Syntax error

b)

Other error

c)

Semantic error

d)

Runtime error

73.

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)

a)

Syntax error

b)

Other error

c)

Semantic error

d)

Runtime error

74.

In a function call, if the arguments passed to the function are missing, what type of runtime error occurs?

a)

SyntaxError

b)

NameError

c)

TypeError

d)

No runtime error occurs

75.

What type of exception occurs if the arguments passed to the function are missing?

a)

SyntaxError.

b)

NameError.

c)

TypeError.

d)

No exception occurs.

76.

What exception will the following commands raise? >>> s = abc >>> s[10]

a)

SyntaxError.

b)

NameError.

c)

TypeError.

d)

IndexError.

77.

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?

a)

SyntaxError.

b)

ValueError

c)

TypeError.

d)

IndexError.

78.

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")

a)

ValueError

b)

TypeError.

c)

NameError.

d)

SyntaxError.

79.

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.

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.

80.

What is the exception error code of the command int("abc")?

a)

TypeError

b)

ValueError

c)

NameError

d)

SyntaxError

81.

Which of the following answers is the most correct? Some exception error codes in Python are:

a)

IndexError, NameError, TypeError, ValueError, IndentationError, SyntaxError

b)

ZeroDivisionError, IndexError, NameError, TypeError

c)

NameError, TypeError, ValueError, IndentationError, SyntaxError

d)

ZeroDivisionError, IndexError, NameError, TypeError, ValueError, IndentationError, SyntaxError

82.

The program reports a SyntaxError. What is this error?

a)

Syntax error

b)

Data type error

c)

Value-related error

83.

The program reports a SyntaxError. What is this error?

a)

Syntax error

b)

Data type error

c)

Value-related error

d)

Indentation error

84.

How many types of program errors can be distinguished in Python?

a)

4

b)

1

c)

3

d)

2

85.

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?

a)

Logic error

b)

No error

c)

Syntax error

d)

Runtime error

86.

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:

a)

1 3 5 10 0

b)

The program reports a TypeError

c)

The program reports a NameError

87.

Among the following programs, which program generates a TypeError?

a)

A.

b)

B.

c)

C.

d)

D.

88.

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=" ")

a)

1 3 5 10 0

b)

TypeError

c)

NameError

d)

3 5 10 0

89.

The program reports a ZeroDivisionError, when does this occur?

a)

This error occurs when dividing by 0.

b)

This error occurs when the program tries to find a name but cannot.

c)

This error occurs when trying to access an element of a list but the index exceeds the limit.

d)

This error occurs when the lines of code are not indented correctly.

90.

What is a logic error?

a)

An error that occurs when calling an undeclared variable.

b)

An error that occurs when the program runs incorrectly but does not report an error.

c)

An error that occurs due to incorrect syntax.

d)

An error that occurs when the program cannot run.

91.

When does a TypeError occur?

a)

When calling an undeclared variable.

b)

When dividing a number by 0.

c)

When accessing an empty list.

d)

When using the wrong data type.

92.

What is the result of the following code? x = 10/0 print(x)

a)

0

b)

ZeroDivisionError.

c)

NameError.

93.

What is the result of the following code? x = 10/0 print (x)

a)

0

b)

ZeroDivisionError

c)

NameError

d)

10

94.

What is the result of the following code? x = "5" y = 2 print (x+y)

a)

7

b)

NameError

c)

"52"

d)

TypeError

95.

What happens when the program has a syntax error?

a)

The program runs but the result is wrong.

b)

The program ignores the error and continues executing.

c)

The program stops immediately and reports an error.

d)

The program runs slower than usual.

96.

In which case does a NameError usually occur?

a)

When dividing a number by 0.

b)

When calling a variable that has not been declared.

c)

When accessing an element that is not in the list.

d)

When there is a syntax error.

97.

What is the result of the following code? list = [1,2,3,4] print (list[5])

a)

IndexError

b)

5

c)

1

d)

NameError

98.

What error occurs when writing incorrect syntax in Python?

a)

SyntaxError

b)

Logic error

c)

RuntimeError

d)

Data type error

99.

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"

a)

Find errors, prevent, stop.

b)

Find errors, prevent, handle.

c)

Prevent, stop, handle errors.

d)

Handle errors, prevent, stop.

100.

Which of the following is not a tool for testing programs?

a)

Intermediate variable printing tool.

b)

Test data set generation tool.

c)

Data statistics tool.

d)

Breakpoint tool in programming software.

101.

Which statement is most accurate when talking about test data sets in program testing?

a)

Test sets can have inputs according to different criteria.

b)

Test sets have inputs according to certain criteria.

c)

Test sets can have inputs according to different criteria such as size, data diversity.

d)

Test sets must have inputs according to criteria about size, data diversity.

102.

Chương trình chạy phát sinh lỗi ngoại lệ ZeroDivision, nên xử lí như thế nào?

a)

Kiểm tra lại giá trị số chia.

b)

Kiểm tra lại chỉ số trong mảng.

c)

Kiểm tra giá trị của số bị chia.

d)

Kiểm tra kiểu dữ liệu nhập vào.

103.

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?

a)

Hiện nay, có ít phương pháp và công cụ khác nhau để kiểm thử chương trình.

b)

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ác bộ test phụ thuộc vào các tiêu chí khác nhau.

d)

Các bộ test dữ liệu nên có nhiều bộ test ngẫu nhiên,...

104.

Chương trình sau phát sinh lỗi gì?

a)

NameError.

b)

TypeError.

c)

ZeroDivisionError.

d)

Syntax Error.

105.

Chương trình chạy phát sinh lỗi ngoại lệ IndexError, nên xử lí như thế nào?

a)

Kiểm tra lại giá trị số chia.

b)

Kiểm tra lại chỉ số trong mảng.

c)

Kiểm tra giá trị của số bị chia.

d)

Kiểm tra kiểu dữ liệu nhập vào.

106.

Chương trình sau có lỗi ở dòng lệnh nào?

a)

1.

b)

2.

c)

3.

d)

4.

107.

Chương trình chạy phát sinh lỗi ngoại lệ TypeError, nên xử lí như thế nào?

a)

Kiểm tra lại chỉ số trong mảng.

b)

Kiểm tra lại giá trị số chia.

c)

Kiểm tra giá trị của số bị chia.

d)

Kiểm tra kiểu dữ liệu nhập vào.

108.

Chương trình chạy phát sinh lỗi ngoại lệ NameError, nên xử lí như thế nào?

a)

Kiểm tra lại chỉ số trong mảng.

b)

Kiểm tra lại tên các biến và hàm.

c)

Kiểm tra giá trị của số bị chia.

d)

Kiểm tra kiểu dữ liệu nhập vào.