Multiple choice quiz about Python - Part 7

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.
  1. Question 1: What is the result of the following expression?
     chr('97') 
    chr(97)
    1. a
      Lỗi
    2. 'a'
      a
    3. Lỗi
      a
    4. 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.
  2. Question 2: What is the result of the following function?
     complex(1+2j) 
    1. Lỗi
    2. first
    3. 2j
    4. 1 + 2j
    Explanation: complex () function returns results in complex numbers.
  3. Question 3: Where are the results of complex () function in the answers below?
    1. 0j
    2. 0 + 0j
    3. 0
    4. 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.
  4. Question 4: Divmod function (a, b) where 'a' and 'b' are integers interpreted as:
    1. (a% b, a // b)
    2. (a // b, a% b)
    3. (a // b, a * b)
    4. (a / b, a% b)
    Explanation: The divmod (a, b) function is interpreted as a // b, a% b if both 'a' and 'b' are integers.
  5. Question 5: What is the output of the representation function below?
     divmod(10.5,5) 
    divmod(2.4,1.2)
    1. (2.00, 0.50)
      (2.00, 0.00)
    2. (2, 0.5)
      (2, 0)
    3. (2.0, 0.5)
      (2.0, 0.0)
    4. (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.
  6. 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.
    1. It's correct
    2. 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.
  7. Question 7: What is the result of the function shown below?
     list(enumerate([2, 3])) 
    1. Lỗi
    2. [(1, 2), (2, 3)]
    3. [(0, 2), (1, 3)]
    4. [(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)].
  8. Question 8: What is the result of the function shown below?
     x=3 
    eval('x^2')
    1. Lỗi
    2. first
    3. 9
    4. 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.
  9. Question 9: What is the output of the following function?
     float('1e-003') 
    float('2e+003')
    1. 3.00
      300
    2. 0.001
      2000.0
    3. 0.001
      200
    4. 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.
  10. Question 10: Which of the following functions does not accept iterable as a parameter?
    1. enumerate ()
    2. all ()
    3. chr ()
    4. 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.
5 ★ | 1 Vote