Review questions, analyze choices, and reveal correct answers at your own pace.
1. What does the function math.frexp(x) return?
A. a tuple containing the mantissa and the exponent of x
B. a list containing the mantissa and the exponent of x
C. a tuple containing the mantissa of x
D. a list containing the exponent of x
Correct Option: a tuple containing the mantissa and the exponent of x
2. What is the result of math.fsum([.1 for i in range(20)])?
A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Correct Option: 2.0
3. What is the result of sum([.1 for i in range(20)])?
A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Correct Option: 2.0000000000000004
4. What is returned by math.isfinite(float(‘inf’))?
A. True
B. False
C. None
D. error
Correct Option: False
5. What is returned by math.isfinite(float(‘nan’))?
A. True
B. False
C. None
D. error
Correct Option: False
6. What is x if x = math.isfinite(float(‘0.0’))?
A. True
B. False
C. None
D. error
Correct Option: True
7. What will be the output of the following Python code?
>>> -float('inf') + float('inf')
A. inf
B. nan
C. 0
D. 0.01 to 20%
Correct Option: nan
8. What will be the output of the following Python code?
print(math.isinf(float('-inf')))
A. error, the minus sign shouldn’t have been inside the brackets
B. error, there is no function called isinf
C. True
D. False
Correct Option: True
9. What is the value of x if x = math.ldexp(0.5, 1)?
A. 1
B. 2.0
C. 0.5
D. none of the mentioned
Correct Option: none of the mentioned
10. What is returned by math.modf(1.0)?
A. (0.0, 1.0)
B. (1.0, 0.0)
C. (0.5, 1)
D. (0.5, 1.0)
Correct Option: (0.0, 1.0)
11. What is the result of math.trunc(3.1)?
A. 3.0
B. 3
C. 0.1
D. 1
Correct Option: 3
12. What is the output of print(math.trunc(‘3.1’))?
A. 3
B. 3.0
C. error
D. none of the mentioned
Correct Option: error
13. Which of the following is the same as math.exp(p)?
A. e ** p
B. math.e ** p
C. p ** e
D. p ** math.e
Correct Option: math.e ** p
14. What is returned by math.expm1(p)?
A. (math.e ** p) – 1
B. math.e ** (p – 1)
C. error
D. none of the mentioned
Correct Option: (math.e ** p) – 1
15. What is the default base used when math.log(x) is found?
A. e
B. 10
C. 2
D. none of the mentioned
Correct Option: e
16. Which of the following aren’t defined in the math module?
A. log2()
B. log10()
C. logx()
D. none of the mentioned
Correct Option: logx()
17. What is returned by int(math.pow(3, 2))?
A. 6
B. 9
C. error, third argument required
D. error, too many arguments
Correct Option: 9
18. What is the value of x if x = math.sqrt(4)?
A. 2
B. 2.0
C. (2, -2)
D. (2.0, -2.0)
Correct Option: 2.0
19. What does math.sqrt(X, Y) do?
A. calculate the Xth root of Y
B. calculate the Yth root of X
C. error
D. return a tuple with the square root of X and Y
Correct Option: error
20. What will be the output of the following Python code?
import datetime
d=datetime.date(2016,7,24)
print(d)
A. Error
B. 2017-07-24
C. 2017-7-24
D. 24-7-2017
Correct Option: 2017-07-24
21. What will be the output of the following Python code?
import datetime
d=datetime.date(2017,06,18)
print(d)
A. Error
B. 2017-06-18
C. 18-06-2017
D. 06-18-2017
Correct Option: Error
22. What will be the output of the following Python code if the system date is 18th August, 2016?
tday=datetime.date.today()
print(tday.month())
A. August
B. Aug
C. 08
D. 8
Correct Option: 8
23. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?
import datetime
tday=datetime.date.today()
print(tday)
A. 18-06-2017
B. 06-18-2017
C. 2017-06-18
D. error
Correct Option: 2017-06-18
24. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?
tday=datetime.date.today()
print(tday.weekday())
A. 6
B. 1
C. 0
D. 7
Correct Option: 6
25. What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?
tday=datetime.date.today()
print(tday.isoweekday())
A. Wed
B. Wednesday
C. 2
D. 3
Correct Option: 3
26. Point out the error (if any) in the code shown below if the system date is 18th June, 2017?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
till_bday=bday-tday
print(till_bday)
A. 3 months, 0:00:00
B. 90 days, 0:00:00
C. 3 months 2 days, 0:00:00
D. 92 days, 0:00:00
Correct Option: 92 days, 0:00:00
27. The value returned when we use the function isoweekday() is ______ and that for the function weekday() is ________ if the system date is 19th June, 2017 (Monday).
A. 0,0
B. 0,1
C. 1,0
D. 1,1
Correct Option: 1,0
28. Which of the following will throw an error if used after the following Python code?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
t_day=bday-tday
A. print(t_day.seconds)
B. print(t_day.months)
C. print(t_day.max)
D. print(t_day.resolution)
Correct Option: print(t_day.months)
29. What will be the output of the following Python code if the system date is: 6/19/2017
tday=datetime.date.today()
tdelta=datetime.timedelta(days=10)
print(tday+tdelta)
A. 2017-16-19
B. 2017-06-9
C. 2017-06-29
D. error
Correct Option: 2017-06-29
30. Which of the following functions can be used to find the coordinated universal time, assuming that the datetime module has already been imported?
A. datetime.utc()
B. datetime.datetime.utc()
C. datetime.utcnow()
D. datetime.datetime.utcnow()
Correct Option: datetime.datetime.utcnow()
31. What will be the output of the following Python code?
import time
time.time()
A. The number of hours passed since 1st January, 1970
B. The number of days passed since 1st January, 1970
C. The number of seconds passed since 1st January, 1970
D. The number of minutes passed since 1st January, 1970
Correct Option: The number of seconds passed since 1st January, 1970
32. What will be the output of the following Python code?
import time
time.asctime()
A. Current date only
B. UTC time
C. Current date and time
D. Current time only
Correct Option: Current date and time
33. What will be the output of the following Python code?
import time
t=(2010, 9, 20, 8, 15, 12, 6)
time.asctime(t)
A. ‘20 Sep 2010 8:15:12 Sun’
B. ‘2010 20 Sept 08:15:12 Sun’
C. ‘Sun Sept 20 8:15:12 2010’
D. error
Correct Option: error
34. What will be the output of the following Python code?
import time
t=(2010, 9, 20, 8, 45, 12, 6, 0, 0)
time.asctime(t)
A. ‘Sep 20 2010 08:45:12 Sun’
B. ‘Sun Sep 20 08:45:12 2010’
C. ’20 Sep 08:45:12 Sun 2010’
D. ‘2010 20 Sep 08:45:12 Sun’
Correct Option: ‘Sun Sep 20 08:45:12 2010’
35. The sleep function (under the time module) is used to ____
A. Pause the code for the specified number of seconds
B. Return the specified number of seconds, in terms of milliseconds
C. Stop the execution of the code
D. Return the output of the code had it been executed earlier by the specified number of seconds
Correct Option: Pause the code for the specified number of seconds
36. What will be the output of the following Python code?
import time
for i in range(0,5):
print(i)
time.sleep(2)
A. After an interval of 2 seconds, the numbers 1, 2, 3, 4, 5 are printed all together
B. After an interval of 2 seconds, the numbers 0, 1, 2, 3, 4 are printed all together
C. Prints the numbers 1, 2, 3, 4, 5 at an interval of 2 seconds between each number
D. Prints the numbers 0, 1, 2, 3, 4 at an interval of 2 seconds between each number
Correct Option: Prints the numbers 0, 1, 2, 3, 4 at an interval of 2 seconds between each number
37. What will be the output if we try to extract only the year from the following Python code? (time.struct_time(tm_year=2017, tm_mon=6, tm_mday=25, tm_hour=18, tm_min=26, tm_sec=6, tm_wday=6, tm_yday=176, tm_isdst=0))
import time
t=time.localtime()
print(t)
A. t[1]
B. tm_year
C. t[0]
D. t_year
Correct Option: t[0]
38. To include the use of functions which are present in the random library, we must use the option:
A. import random
B. random.h
C. import.random
D. random.random
Correct Option: import random
39. What will be the output of the following Python code?
import random
random.choice(2,3,4)
A. An integer other than 2, 3 and 4
B. Either 2, 3 or 4
C. Error
D. 3 only
Correct Option: Error
40. What will be the output of the following Python code?
import random
random.choice([10.4, 56.99, 76])
A. Error
B. Either 10.4, 56.99 or 76
C. Any number other than 10.4, 56.99 and 76
D. 56.99 only
Correct Option: Either 10.4, 56.99 or 76
41. What will be the output of the following Python function (random module has already been imported)?
random.choice('sun')
A. sun
B. u
C. either s, u or n
D. error
Correct Option: either s, u or n
42. What will be the output of the following Python function, assuming that the random module has already been imported?
random.uniform(3,4)
A. Error
B. Either 3 or 4
C. Any integer other than 3 and 4
D. Any decimal value between 3 and 4
Correct Option: Any decimal value between 3 and 4
43. What will be the output of the following Python function if the random module has already been imported?
random.randint(3.5,7)
A. Error
B. Any integer between 3.5 and 7, including 7
C. Any integer between 3.5 and 7, excluding 7
D. The integer closest to the mean of 3.5 and 7
Correct Option: Error
44. Which of the following functions helps us to randomize the items of a list?
A. seed
B. randomise
C. shuffle
D. uniform
Correct Option: shuffle
45. What will be the output of the following Python code?
random.seed(3)
random.randint(1,5)
2
random.seed(3)
random.randint(1,5)
A. 3
B. 2
C. Any integer between 1 and 5, including 1 and 5
D. Any integer between 1 and 5, excluding 1 and 5
Correct Option: 2
46. What is the interval of the value generated by the function random.random(), assuming that the random module has already been imported?
A. (0,1)
B. (0,1]
C. [0,1]
D. [0,1)
Correct Option: [0,1)
47. What will be the output of the following Python code?
random.randrange(0,91,5)
A. 10
B. 18
C. 79
D. 95
Correct Option: 10
48. Both the functions randint and uniform accept ____________ parameters.
A. 0
B. 1
C. 3
D. 2
Correct Option: 2
49. What will be the output of the following Python code?
random.randrange(1,100,10)
A. 32
B. 67
C. 91
D. 80
Correct Option: 91
50. What will be the output of the following Python function, assuming that the random library has already been included?
random.shuffle[1,2,24]
A. Randomized list containing the same numbers in any order
B. The same list, that is [1,2,24]
C. A list containing any random numbers between 1 and 24