Following the previous test set, Part 7 continues with the topic Built-in functions in Python. Let's try with Quantrimang to try the 10 questions below.
Question 1: What is the result of the following expression?
chr('97') chr(97)
a Lỗi
'a' a
Lỗi a
Lỗi Lỗi
Explanation: The chr () function returns the letter corresponding to the value provided as a parameter. This function only accepts integer type values. In the first function, we passed a string. Therefore the first function returns an error.
Question 2: What is the result of the following function?
complex(1+2j)
Lỗi
first
2j
1 + 2j
Explanation: complex () function returns results in complex numbers.
Question 3: Where are the results of complex () function in the answers below?
0j
0 + 0j
0
Lỗi
Explanation: The complex () function returns 0j if both parameters are omitted, meaning that if the function is in complex () or complex (0), the output will be 0j.
Question 4: Divmod function (a, b) where 'a' and 'b' are integers interpreted as:
(a% b, a // b)
(a // b, a% b)
(a // b, a * b)
(a / b, a% b)
Explanation: The divmod (a, b) function is interpreted as a // b, a% b if both 'a' and 'b' are integers.
Question 5: What is the output of the representation function below?
divmod(10.5,5) divmod(2.4,1.2)
(2.00, 0.50) (2.00, 0.00)
(2, 0.5) (2, 0)
(2.0, 0.5) (2.0, 0.0)
(2, 0.5) (2)
Explanation: The divmod () function in Python returns a tuple including quotient and balance when parameter 1 is divided by parameter 2.
Question 6: Is the following statement true or false?
The expression complex ('2-3j') is valid and complex ('2 - 3j') is the wrong syntax of the complex () function.
It's correct
False
Explanation: When converting from a string, the string must not contain any spaces around the + or - operator. Therefore, complex function ('2 - 3j') will lead to an error.
Question 7: What is the result of the function shown below?
list(enumerate([2, 3]))
Lỗi
[(1, 2), (2, 3)]
[(0, 2), (1, 3)]
[(2, 3)]
Explanation: The enumerate () function accepts iterable as a parameter, in case the function requires returning an array list with its index starting from 0. Therefore, the output will be: [(0 , 2), (1,3)].
Question 8: What is the result of the function shown below?
x=3 eval('x^2')
Lỗi
first
9
6
Explanation: The eval function is used to evaluate the expression it uses as a parameter. In the above case, the eval () function is used to perform the XOR operation between 3 and 2. Therefore the output is 1.
Question 9: What is the output of the following function?
float('1e-003') float('2e+003')
3.00 300
0.001 2000.0
0.001 200
Lỗi 2003
Explanation: The output of the first function will be 0.001 and the second function will be 2000.0. The first function creates a number of floating points up to 3 decimal places and the second function adds three zeroes after the given number.
Question 10: Which of the following functions does not accept iterable as a parameter?
enumerate ()
all ()
chr ()
max ()
The functions enumerate (), all () and max () accept iterable as a parameter while the chr () function will get an error when receiving iterable as a parameter. Also note that the chr () function only accepts integer values.