Font size
Worksheetsfailure
Total questions: 61
Worksheet time: 33mins
The number of arguments that can be passed to a function is
1
1 or more
0
0 or more
The two types of functions used in Pythons are
System function
User function and system call
Builts-in and user-defined
Custom function and user function
The variable defined outside the function is referred as
automatic
register
global
static
The default arguments specified in the function header is an
Identifier followed by an #
Identifier followed by the default value within back-ticks
Identifier followed by the default value within []
Identifier followed by an = and the default value
Explain the output of the following program
Pi = 3.14
Def tt_hinh_non(bk =10, h = 10):
Print(pi*bk*bk*k)
Print(tt_hinh_non(5,5))
a. The variable pi is placed outside the function
a. The arguments are not the same as the default parameter
a. Two nested print() statements
a. The function don’t have a return statement
Guess the value of x with the below code:
Import math
X = math.sqrt(36)
6.0
6
-6
error
A local variable in Python is a variable that is
Defined inside every function
Local to the given program
Accessible from within the function
All of these
Which of the following logical operations are used in a while loop?
True, False
and, or, but
and, neither, nor
and, or, not
When running the program, if the user enters 2003 and 2023 respectively, what is the last line in the program execution result?
Def tinh_tuoi(ns, nht):
Tuoi = nht – ns
Print (f”{nht} – {ns} =”)
Print((tuoi)
Nam_sinh = int(input())
Nam_hien_tai = int(input())
Print(tinh_tuoi(nam_sinh, nam_hien_tai)
None
2023
20
a. 2023 -2020 =
Corresponding to the function call. Print (KQ(TD(7.5, 6.5, 8.5, 1, 1 2)))
Def TD(t, v, c, s1 = 1, s2 = 1, s3 = 1):
Return t*s1 + v*s2 +c*s3
Def KQ(d):
If d >= 24:
Return “Học bổng”
Elif d >= 20:
Reuturn “Đỗ”
Else:
Return “Trượt”
Học bổng
Đỗ
Trượt
31.0
Which statement is correct about the while loop in Python?
You cannot have a while loop nested within another while loop
The condition in while cannot have logical operations and/or/not
Repeatedly execute a block of statements while a condition is true
In the while loop, the break statement can be used
Which statement is correct about using for loop in Python?
Only use maximum of 2 nested for loops.
Cannot use continue or break statements in a for loop
for is used when a block of code needs to be executed repeatedly a known number of times
for is used when a block of code needs to be executed repeatedly an indenfinite number of times until a condition is met.
Guess the output of the following code if call quad(3):
Def quad(x):
X *=x
X *=x
81
3
9
27
Guess the program as shown below. Where, the variable count is used to count pairs (i,j) with the same parity. Which conditional expression is correct to put in the yellow highlighted area in the statement at line
1 count = 0
2 for i in range (10):
3 for j in range(10):
4 if ________
5 count +=1
6 print(count)
(i % 2 == 0) and (j % 2 == 0)
(i+j) % 2 == 0
(i+j) % 2 != 0
(i % 2 != 0) and (j % 2 != 0)
Which conditional expression of the if statement needs to be filled in the blank part in line 5?
1 count = 0
2 n = 20
3 for num in range(2,n):
4 for i in range(2, int(num/2)+1):
5 if _______________:
6 else:
7 count +=1
8 print(count)
num % 2 == 0
num %i ==0
num%i !=0
num % 2 != 0
Given the program as shown in the following figure. Which option fills in the blank on the line 4 so that the program does not loop infinitely (choose 2 answers):
X = 1
While x < 10:
Print(x)
X ______
*=2
/=2
-=2
+=2
determine the distance between two adjacent values in a list
(a)
All values generated in the list must be less than
(a)
Initial value of the list
(a)
Rearrange the statements below to form a complete program that calculates the sum of odd numbers form 1 to n.
1. for i in range(1, n+1)
2. n = int(input(“Nhap vao mot so:”)
3. s+=i
4. s= 0
5. print(f’s={s}’)
6. if (i%2==1):
2 4 1 3 6 5
2 4 1 6 3 5
4 2 1 3 6 5
4 2 3 1 5 6
what is the output displayes on the screen when the following program is executed?
For num in range(10,14):
For i in range(2, num):
If num%i==0:
Print(num, end = “ “)
Break
10 12
Nothing on the screen
10 11 12 13
10 11 12 13 14
What is the value of variable x after executing the following program?
X= 0
For i in range (10):
For j in range (-1,-10,-1):
X+=1
100
90
99
101
The function divmod(10,20) is evaluated as
(10//20, 10%20)
(10/20, 10%20)
(10%20, 10//20)
(10//20,10*20)
Assume the list superstore is [1,2,3,4,5] which of the following is correct syntax for slicing operation?
print(superstore[0:])
print(superstore[:2])
print(superstore[:-2])
All of these
The list function that inserts the item at the given index after shifting the items to the right is
append()
insert()
sort()
index()
What will be the output of the following?
1
4
2
5
There is a list A = [1,3,5,7,9,11], which of the following syntax is the best correct to get a sublist
A[1:-2]
A[1:3]
A[1:]
All of these
Suppose continents = [1,2,3,4,5], what is the output of len(continents)?
4
5
error
none
To insert the string “snake” to the third position in list zoo, which of the following statement is used?
zoo.insert(2, “snake”)
zoo.append(3, “snake”)
zoo.insert(3, "snake”)
zoo.add(3, “snake”)
The method that is used to count the number of times an item has occurred in the list is
len()
count()
extend()
length()
Find the output of the following code:
33
3
6
5
. Assume quantity = [3,4,5,20, 5, 25,1,3] then what will be the items of quantity list after quantity.pop(1)
[3,4,5,20,5,25,1,3]
[3,5,20,5,25,1,3]
[1,3,3,4,5,5,20, 25]
[1,3,4,5,20,5,25]
What is the correct way to define a function in Python?
def function_name:
function function_name():
def function_name():
define function_name():
Which of the following is NOT a built-in data type in Python?
List
Dictionary
Tuple
Tree
How can you remove an element from a list in Python?
remove()
del()
pop()
all of the above
What is the default return value of a function that does not have a return statement?
0
None
False
" "(empty string)
What will print("Hello"[::-1]) output?
Hello
olleH
H e l l o
SyntaxError
Which of the following methods can be used to check if a key exists in a dictionary?
key in dict
dict.has_key(key)
dict.contains(key)
exists(dict, key)
What will print(bool([])) output?
True
False
None
[]
What will print(type(5.0)) output?
<class 'int'>
<class 'float'>
<class 'double'>
<class 'number'>
output?
def test(x, y=[]):
y.append(x)
return y
print(test(1))
print(test(2))
[1], [2]
[1], [1, 2]
[1, 2], [1, 2]
[1, 2], [2]
output:
print("Python"[2:5])
tho
yth
tho
tho
def func(a, b=10):
return a + b
print(func(5))
5
10
15
Error
What does print(list(range(3, 10, 2))) output?
[3, 4, 5, 6, 7, 8, 9]
[3, 5, 7, 9]
[3, 6, 9]
[3, 10]
s = "abcdef"
print(s[:4] + s[4:])
abcd ef
abcdef
abcd
Error
What will print("hello".capitalize()) output?
hello
Hello
HELLO
hELLO
What will print("A B C".split()) output?
['A', 'B', 'C']
['A B C']
['A', ' B', ' C']
['A', '', 'B', '', 'C']
. What does the following code output?
def f(x=[]):
x.append(1)
return x
print(f())
print(f())
[1] [1]
[1] [1, 1]
[1, 1] [1]
[1, 1] [1, 1]
What is the correct syntax for an if-else statement in Python?
if condition { } else { }
if condition: else:
if condition: ... elif condition: ... else:
if condition then ... else then ...
x = 10
if x > 5:
print("A")
elif x > 8:
print("B")
else:
print("C")
A
B
C
No output
Which statement about Python loops is true?
for loops require a predefined number of iterations
while loops always execute at least once
break exits the loop but continue stops the program
Python does not support for loops
What does the else clause in a while loop do?
Executes only if the loop is broken with break
Executes if the loop runs at least once
Executes if the loop condition becomes False naturally
Executes before the loop starts
. What will for i in "hello": print(i) output?
h e l l o
hello
h on one line, then e, then l, etc.
olleh
Which of the following is NOT a valid way to iterate through a string?
for char in "hello": print(char)
for i in range(len("hello")): print("hello"[i])
while "hello": print("loop")
"hello".split() and iterating through the list
What does range(3, 10, 2) produce?
[3, 4, 5, 6, 7, 8, 9]
[3, 5, 7, 9]
[3, 6, 9]
. [3, 10]
What will print("hello".replace('l', 'L', 1)) output?
heLLo
heLlo
heLLo
Error
def mystery(n):
if n == 1:
return 1
else:
return n * mystery(n - 1)
print(mystery(4))
10
24
15
12
. x = 5
if x == 5 and not (x > 10 or x < 3):
print("A")
elif x < 10:
print("B")
else:
print("C")
A
B
C
A B
How many times will the while loop execute
x = 0
while x < 10:
x += 2
print("Done")
10 times
5 times
infinite times
6 times
What is the final value of count after execution?
count = 0
for i in range(4):
for j in range(i):
count += 1
print(count)
4
6
3
5
for i in range(10, 0, -3):
print(i, end=" ")
10 7 4
10 8 6 4 2
10 9 8 7 6 5 4 3 2 1
10 7 4 1
