4 Bio

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Which of the following functions is a built-in function in python?

a) seed() b) sqrt() c) factorial() d) print()


Answer: d
EXPLANATION: The function seed is a function which is present in the random module. The functions
sqrt and factorial are a part of the math module. The print function is a built-in function which prints a
value directly to the system output.

2. What is the output of the expression:


round(4.576)
a) 4.5 b) 5 c) 4 d) 4.6
Answer: b
EXPLANATION: This is a built-in function which rounds a number to give precision in decimal digits.
In the above case, since the number of decimal places has not been specified, the decimal number is
rounded off to a whole number. Hence the output will be 5.

3. The function pow(x,y,z) is evaluated as:


a) (x**y)**z b) (x**y) / z
c) (x**y) % z d) (x**y)*z
Answer: c
EXPLANATION: The built-in function pow() can accept two or three arguments. When it takes in two
arguments, they are evaluated as: x**y. When it takes in three arguments, they are evaluated as:
(x**y)%z.

4. What is the output of the function shown below? all([2,4,0,6])


a) Error b) True c) False c) 0
Answer: c
EXPLANATION: The function all returns false if any one of the elements of the iterable is zero and true
if all the elements of the iterable are non zero. Hence the output of this function will be false.

5. What is the output of the expression?


round(4.5676,2)?
a) 4.5 b) 4.6 c) 4.57 d) 4.56 Answer: c
EXPLANATION: The function round is used to round off the given decimal number to the specified
decimal places. In this case the number should be rounded off to two decimal places. Hence the output
will be 4.57.

6. What is the output of the following function?


any([2>8, 4>2, 1>2])
a) Error b) True c) False d) 4>2
Answer: b
EXPLANATION: The built-in function any() returns true if any or more of the elements of the iterable is
true (non zero), If all the elements are zero, it returns false.

7. What is the output of the function shown below?


import math abs(math.sqrt(25))
a) Error b) -5 c) 5 d) 5.0
Answer: d
EXPLANATION: The abs() function prints the absolute value of the argument passed. For example:
abs(-5)=5. Hence , in this case we get abs(5.0)=5.0.

8. What are the outcomes of the functions shown below? sum(2,4,6) sum([1,2,3])
a) Error, 6 b) 12, Error c) 12, 6 d) Error, Error Answer: a
EXPLANATION: The first function will result in an error because the function sum() is used to find the
sum of iterable numbers. Hence the outcomes will be Error and 6 respectively.

9. What is the output of the function:


all(3,0,4.2)
a) True b) False c) Error d) 0
Answer: c
EXPLANATION: The function all() returns ‘True’ if any one or more of the elements of the iterable are
non zero. In the above case, the values are not iterable, hence an error is thrown.

10. What is the output of the functions shown below?


min(max(False,-3,-4), 2,7)
a) 2 b) False c) -3 d) -4
Answer: b
EXPLANATION: The function max() is being used to find the maximum value from among -3, -4 and
false. Since false amounts to the value zero, hence we are left with min(0, 2, 7) Hence the output is 0
(false).
2
1. What are the outcomes of the following functions?
chr(‘97’) chr(97)
a) a and Erro b) ‘a’ c) Error d) Error
Error
Answer: c
EXPLANATION: The built-in function chr() returns the alphabet corresponding to the value given as an
argument. This function accepts only integer type values. In the first function, we have passed a string.
Hence the first function throws an error.

2. What is the output of the following function?


complex(1+2j)
a) Error b) 1 c) 2j d) 1+2j
Answer: d
EXPLANATION: The built-in function complex() returns the argument in a complex form. Hence the
output of the function shown above will be 1+2j.

3. What is the output of the function complex() ?


a) 0j b) 0+0j c) 0 d) Error Answer: a
EXPLANATION: The complex function returns 0j if both of the arguments are omitted, that is, if the
function is in the form of complex() or complex(0), then the output will be 0j.
4. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
a) (a%b, a//b) b) (a//b, a%b)
c) (a//b, a*b) c) (a/b, a%b)
Answer: b
EXPLANATION: The function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers.

5. What is the output of the functions shown below? divmod(10.5,5) divmod(2.4,1.2)


a) (2.00, 0.50) and (2.00, 0.00) b) (2, 0.5) and (2, 0)
c) (2.0, 0.5) and (2.0, 0.0) d) (2, 0.5) and (2)
Answer: c
EXPLANATION: See python documentation for the function divmod.

6. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid. State whether
this statement is true or false. a) True b) False
Answer: a
EXPLANATION: When converting from a string, the string must not contain any blank spaces around
the + or – operator. Hence the function complex(‘2 – 3j’) will result in an error.
6. What is the output of the function shown below? list(enumerate([2,
3]))
a) Error b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)] d) [(2, 3)]
Answer: c
EXPLANATION: The built-in function enumerate() accepts an iterable as an argument. The function
shown in the above case returns containing pairs of the numbers given, starting from 0. Hence the output
will be: [(0, 2), (1,3)].

To open a file c:\scores.txt for reading, we use


a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)
Answer: b
EXPLANATION: Execute help(open) to get more details.

2. To open a file c:\scores.txt for writing, we use


a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
Answer: b
EXPLANATION: w is used to indicate that file is to be written to.
3. To open a file c:\scores.txt for appending data, we use
a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
Answer: a
EXPLANATION: a is used to indicate that data is to be appended.

You might also like