Explore topic-wise MCQs in Technical Programming.

This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.

301.

Which of the following is a possible outcome of the function shown below? random.randrange(0,91,5)

A. 10
B. 18
C. 79
D. 95
Answer» B. 18
302.

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)
Answer» E.
303.

What is the output of the code shown below? 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
Answer» C. Any integer between 1 and 5, including 1 and 5
304.

Which of the following functions helps us to randomize the items of a list?

A. seed
B. randomise
C. shuffle
D. uniform
Answer» D. uniform
305.

What is the output of the function shown below 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
Answer» B. Any integer between 3.5 and 7, including 7
306.

What is the output of the following 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
Answer» E.
307.

What is the output of the function shown below (random module has already been imported)? random.choice('sun')

A. sun
B. u
C. either s, u or n
D. error
Answer» D. error
308.

What is the output of the code shown below? 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
Answer» C. Any number other than 10.4, 56.99 and 76
309.

What is the output of the code shown below? 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
Answer» D. 3 only
310.

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
Answer» B. random.h
311.

The output of the code shown below is 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) Code: To extract only the year from this, we can use the function: import time t=time.localtime() print(t)

A. t[1]
B. tm_year
C. t[0]
D. t_year
Answer» D. t_year
312.

The output of the code shown will be: 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
Answer» E.
313.

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
Answer» B. Return the specified number of seconds, in terms of milliseconds
314.

What is the output of the code shown below? 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’
Answer» C. ’20 Sep 08:45:12 Sun 2010’
315.

What is the output of the code shown below? 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
Answer» E.
316.

The output of the code shown below: import time time.asctime()

A. Current date only
B. UTC time
C. Current date and time
D. Current time only
Answer» D. Current time only
317.

What is the output of the following code, if the time module has already been imported? def num(m): t1 = time.time() for i in range(0,m): print(i) t2 = time.time() print(str(t2-t1)) num(3)

A. 1 2 3 The time taken for the execution of the code
B. 3 The time taken for the execution of the code
C. 1 2 3 UTC time
D. 3 UTC time
Answer» B. 3 The time taken for the execution of the code
318.

What is the output of the code shown below? 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
Answer» D. The number of minutes passed since 1st January, 1970
319.

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()
Answer» E.
320.

What is the output of the code shown below 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
Answer» D. Error
321.

Which of the following will throw an error if used after the code shown below? 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)
Answer» C. print(t_day.max)
322.

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
Answer» D. 1,1
323.

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
Answer» E.
324.

What is the output of the following 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
Answer» E.
325.

What is the output of the code shown below if the system date is 18th June, 2017 (Sunday)? tday=datetime.date.today() print(tday.weekday())

A. 6
B. 1
C. 0
D. 7
Answer» B. 1
326.

What is the output of the code shown 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
Answer» D. Error
327.

What is the output of the code shown below if the system date is 18th August, 2016? tday=datetime.date.today() print(tday.month())

A. August
B. Aug
C. 08
D. 8
Answer» E.
328.

What is the output of the snippet of code shown below? import datetime d=datetime.date(2017,06,18) print(d)

A. Error
B. 2017-06-18
C. 18-06-2017
D. 06-18-2017
Answer» B. 2017-06-18
329.

The output of the snippet of code shown below is: import datetime d=datetime.date(2016,7,24) print(d)

A. Error
B. 2017-07-24
C. 2017-7-24
D. 24-7-2017
Answer» C. 2017-7-24
330.

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
Answer» D. return a tuple with the square root of X and Y
331.

What is the value of x if x = math.sqrt(4)?

A. 2
B. 2.0
C. (2, -2)
D. (2.0, -2.0)
Answer» C. (2, -2)
332.

What is output of print(math.pow(3, 2))?

A. 9
B. 9.0
C. None
D. none of the mentioned
Answer» C. None
333.

What is returned by int(math.pow(3, 2))?

A. 6
B. 9
C. error, third argument required
D. error, too many arguments
Answer» C. error, third argument required
334.

Which of the following aren’t defined in the math module?

A. log2()
B. log10()
C. logx()
D. none of the mentioned
Answer» D. none of the mentioned
335.

What is the default base used when math.log(x) is found?

A. e
B. 10
C. 2
D. none of the mentioned
Answer» B. 10
336.

What is returned by math.expm1(p)?

A. (math.e ** p) – 1
B. math.e ** (p – 1)
C. error
D. none of the mentioned
Answer» B. math.e ** (p – 1)
337.

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
Answer» C. p ** e
338.

What is the output of print(math.trunc(‘3.1’))?

A. 3
B. 3.0
C. error
D. none of the mentioned
Answer» D. none of the mentioned
339.

What is the result of math.trunc(3.1)?

A. 3.0
B. 3
C. 0.1
D. 1
Answer» C. 0.1
340.

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)
Answer» B. (1.0, 0.0)
341.

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
Answer» E.
342.

What is the output of the following? 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
Answer» D. False
343.

What is the result of the following? >>> -float('inf') + float('inf')

A. inf
B. nan
C. 0
D. 0.0
Answer» C. 0
344.

What is x if x = math.isfinite(float(‘0.0’))?

A. True
B. False
C. None
D. error
Answer» B. False
345.

What is returned by math.isfinite(float(‘nan’))?

A. True
B. False
C. None
D. error
Answer» C. None
346.

What is returned by math.isfinite(float(‘inf’))?

A. True
B. False
C. None
D. error
Answer» C. None
347.

What is the result of sum([.1 for i in range(20)])?

A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Answer» E.
348.

What is the result of math.fsum([.1 for i in range(20)])?

A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Answer» B. 20
349.

What does the function math.frexp(x) return?

A. a tuple containing of the mantissa and the exponent of x
B. a list containing of the mantissa and the exponent of x
C. a tuple containing of the mantissa of x
D. a list containing of the exponent of x
Answer» B. a list containing of the mantissa and the exponent of x
350.

What is math.floor(0o10)?

A. 8
B. 10
C. 0
D. 9
Answer» B. 10