QUIZ ON : PROGRAMMING AND PROBLEM SOLVING THROUGH PYTHON - MODULES IN PYTHON

MODULES IN PYTHON

00:00:00

What will be the output of the following Python code?

import random

random.choice(2,3,4)

Option A. An integer other than 2, 3 and 4
Option B. Either 2, 3 or 4
Option C. Error
Option D. 3 only
True Answer C

Explanation :
The code shown above displays the incorrect syntax of the function random.choice(). This functions takes its numeric parameter in the form of a list. Hence the correct syntax world be: random.choice([2,3,4]).

What will be the output of the following Python code?

import random

random.choice(2,3,4)

Question No# : 01 out of 20



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())

Option A. August
Option B. Aug
Option C. 08
Option D. 8
True Answer D

Explanation :
The code shown above prints the month number from the system date. Therefor the output will be 8 if the system date is 18th August, 2016.

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())

Question No# : 02 out of 20



Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?

Option A. 0
Option B. 1
Option C. KeyError: 1
Option D. none of the mentioned
True Answer A

Explanation :
It will not print 0 but dict[0] i.e. 1 may be printed.

Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?

Question No# : 03 out of 20



Both the functions randint and uniform accept ____________ parameters.

Option A. 0
Option B. 1
Option C. 3
Option D. 2
True Answer C

Explanation :
Both of these functions, that is, randint and uniform are included in the random module and both of these functions accept 3 parameters. For example: random.uniform(self,a,b) where ‘a’ and ‘b’ specify the range and self is an imaginary parameter.

Both the functions randint and uniform accept ____________ parameters.

Question No# : 04 out of 20



What will be the output of the following Python function, assuming that the random module has already been imported?

random.uniform(3,4)

Option A. Error
Option B. Either 3 or 4
Option C. Any integer other than 3 and 4
Option D. Any decimal value between 3 and 4
True Answer D

Explanation :
This question depicts the basic difference between the functions random.randint(a, b) and random.uniform(a, b). While random.randint(a,b) generates an integer between ‘a’ and ‘b’, including ‘a’ and ‘b’, the function random.uniform(a,b) generates a decimal value between ‘a’ and ‘b’.

What will be the output of the following Python function, assuming that the random module has already been imported?

random.uniform(3,4)

Question No# : 05 out of 20



Which type of elements are accepted by random.shuffle()?

Option A. strings
Option B. lists
Option C. tuples
Option D. integers
True Answer B

Explanation :
Strings and tuples are immutable and an integer has no len().

Which type of elements are accepted by random.shuffle()?

Question No# : 06 out of 20



Which of the following cannot be returned by random.randrange(4)?

Option A. 0
Option B. 3
Option C. 2.3
Option D. none of the mentioned
True Answer C

Explanation :
Only integers can be returned.

Which of the following cannot be returned by random.randrange(4)?

Question No# : 07 out of 20



What will be the output of the following Python code?

import time

  t=(2010, 9, 20, 8, 15, 12, 6) 

time.asctime(t)

Option A. ‘20 Sep 2010 8:15:12 Sun’
Option B. ‘2010 20 Sept 08:15:12 Sun’
Option C. ‘Sun Sept 20 8:15:12 2010’
Option D. Error
True Answer D

Explanation :
The code shown above results in an error because this function accepts exactly 9 arguments (including day of the year and DST), but only 7 are given. Hence an error is thrown.

What will be the output of the following Python code?

import time

  t=(2010, 9, 20, 8, 15, 12, 6) 

time.asctime(t)

Question No# : 08 out of 20



What is the range of values that random.random() can return?

Option A. [0.0, 1.0]
Option B. (0.0, 1.0]
Option C. (0.0, 1.0)
Option D. [0.0, 1.0)
True Answer D

Explanation :
Any number that is greater than or equal to 0.0 and lesser than 1.0 can be returned.

What is the range of values that random.random() can return?

Question No# : 09 out of 20



The sleep function (under the time module) is used to ___________

Option A. Pause the code for the specified number of seconds
Option B. Return the specified number of seconds, in terms of milliseconds
Option C. Stop the execution of the code
Option D. Return the output of the code had it been executed earlier by the specified number of seconds
True Answer A

Explanation :
The sleep function (under the time module) is used to pause the code for the specified number of seconds. The number of seconds is taken as an argument by this function.

The sleep function (under the time module) is used to ___________

Question No# : 10 out of 20



What will be the output of the following Python code?

import time

time.asctime()

Option A. Current date only
Option B. UTC time
Option C. Current date and time
Option D. Current time only
True Answer C

Explanation :
The function time.asctime(), present if the time module can be used to return the current date and time. It can also accept a parameter and return the date and time in a particular format. However in the above code, since we have not passed any parameters in the above code, the current date and time is returned.

What will be the output of the following Python code?

import time

time.asctime()

Question No# : 11 out of 20



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)

Option A. 3 months, 0:00:00
Option B. 90 days, 0:00:00
Option C. 3 months 2 days, 0:00:00
Option D. 92 days, 0:00:00
True Answer D

Explanation :
The code shown above can be used to find the number of days between two given dates. The output of the code shown above will thus be 92.

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)

Question No# : 12 out of 20



What will be the output of the following Python code?

import sys

sys.argv[0]

Option A. Junk value
Option B. ‘ ‘
Option C. No output
Option D. Error
True Answer B

Explanation :
The output of the function shown above will be a blank space enclosed in single quotes. Hence the output of the code shown above is ‘ ‘.

What will be the output of the following Python code?

import sys

sys.argv[0]

Question No# : 13 out of 20



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)

Option A. t[1]
Option B. tm_year
Option C. t[0]
Option D. t_year
True Answer C

Explanation :
To extract the year from the code shown above, we use the command t[0]. The command t[1] will return the month number (6 in the above case). The commands tm_year and t_year will result in errors.

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)

Question No# : 14 out of 20



Which of the following is equivalent to random.randint(3, 6)?

Option A. random.choice([3, 6])
Option B. random.randrange(3, 6)
Option C. 3 + random.randrange(3)
Option D. 3 + random.randrange(4)
True Answer D

Explanation :
random.randint(3, 6) can return any one of 3, 4, 5 and 6.

Which of the following is equivalent to random.randint(3, 6)?

Question No# : 15 out of 20



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())

Option A. Wed
Option B. Wednesday
Option C. 2
Option D. 3
True Answer D

Explanation :
This code prints an integer depending on which day of the week it is. Monday-1, Tuesday-2, Wednesday-3, Thursday-4, Friday-5, Saturday-6, Sunday-7. Hence the output of the code shown above is 3.

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())

Question No# : 16 out of 20



To include the use of functions which are present in the random library, we must use the option:

Option A. import random
Option B. random.h
Option C. import.random
Option D. random.random
True Answer A

Explanation :
The command import random is used to import the random module, which enables us to use the functions which are present in the random library.

To include the use of functions which are present in the random library, we must use the option:

Question No# : 17 out of 20



What will be the output of the following Python code?

import time

for i in range(0,5):  	print(i) 

time.sleep(2)

Option A. After an interval of 2 seconds, the numbers 1, 2, 3, 4, 5 are printed all together
Option B. After an interval of 2 seconds, the numbers 0, 1, 2, 3, 4 are printed all together
Option C. Prints the numbers 1, 2, 3, 4, 5 at an interval of 2 seconds between each number
Option D. Prints the numbers 0, 1, 2, 3, 4 at an interval of 2 seconds between each number
True Answer D

Explanation :
The output of the code shown above will be the numbers 0, 1, 2, 3, 4 at an interval of 2 seconds each.

What will be the output of the following Python code?

import time

for i in range(0,5):  	print(i) 

time.sleep(2)

Question No# : 18 out of 20



Which of the following is equivalent to random.randrange(3)?

Option A. range(3)
Option B. random.choice(range(0, 3))
Option C. random.shuffle(range(3))
Option D. random.select(range(3))
True Answer B

Explanation :
It returns one number from the given range.

Which of the following is equivalent to random.randrange(3)?

Question No# : 19 out of 20



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)

Option A. 2017-16-19
Option B. 2017-06-9
Option C. 2017-06-29
Option D. Error
True Answer C

Explanation :
The code shown above will add the specified number of days to the current date and print the new date. On adding ten days to 6/19/2017, we get 6/29/2017. Hence the output is: 2017-06-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)

Question No# : 20 out of 20




CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad