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

MODULES IN PYTHON

00:00:00

Which of the following functions can help us to find the version of python that we are currently working on?

Option A. sys.version
Option B. sys.version()
Option C. sys.version(0)
Option D. sys.version(1)
True Answer A

Explanation :
The function sys.version can help us to find the version of python that we are currently working on. For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along with the version.

Which of the following functions can help us to find the version of python that we are currently working on?

Question No# : 01 out of 20



What will be the output of the following Python code?

import time

time.time()

Option A. The number of hours passed since 1st January, 1970
Option B. The number of days passed since 1st January, 1970
Option C. The number of seconds passed since 1st January, 1970
Option D. The number of minutes passed since 1st January, 1970
True Answer C

Explanation :
The code shown above will return the number of seconds passed since 1st January, 1970.

What will be the output of the following Python code?

import time

time.time()

Question No# : 02 out of 20



What will be the output of the following Python code?

import datetime

    d=datetime.date(2016,7,24) 

print(d)

Option A. Error
Option B. 2017-07-24
Option C. 2017-7-24
Option D. 24-7-2017
True Answer B

Explanation :
In the snippet of code shown above, we are simply printing the date entered by us. We enter the date in the format: yyyy,m,dd. The date is then printed in the format: yyyy-mm-dd. Hence the output is: 2017-07-24.

What will be the output of the following Python code?

import datetime

    d=datetime.date(2016,7,24) 

print(d)

Question No# : 03 out of 20



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

Option A. 6
Option B. 1
Option C. 0
Option D. 7
True Answer A

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

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

Question No# : 04 out of 20



The output of the function len(sys.argv) is ____________

Option A. Error
Option B. 1
Option C. 0
Option D. Junk value
True Answer B

Explanation :
The output of the function sys.argv is [‘ ‘]. When we execute the function len([‘ ‘]), the output is 1. Hence the output of the function len(sys.argv) is also 1.

The output of the function len(sys.argv) is ____________

Question No# : 05 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# : 06 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# : 07 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# : 08 out of 20



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)

Option A. ‘Sep 20 2010 08:45:12 Sun’
Option B. ‘Sun Sep 20 08:45:12 2010’
Option C. ’20 Sep 08:45:12 Sun 2010’
Option D. ‘2010 20 Sep 08:45:12 Sun’
True Answer B

Explanation :
The code shown above returns the given date and time in a particular format. Hence the output of the code shown above will be: ‘Sun Sep 20 08:45:12 2010’.

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)

Question No# : 09 out of 20



What will be the output of the following Python code?

import sys

sys.stdin.readline() 

Sanfoundry

Option A. ‘Sanfoundry ’
Option B. ‘Sanfoundry’
Option C. ‘Sanfoundry10’
Option D. Error
True Answer A

Explanation :
The function shown above works just like raw_input. Hence it automatically adds a ‘ ’ character to the input string. Therefore, the output of the function shown above will be: Sanfoundry .

What will be the output of the following Python code?

import sys

sys.stdin.readline() 

Sanfoundry

Question No# : 10 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# : 11 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# : 12 out of 20



What will be the output of the following Python code?

import random

random.choice([10.4, 56.99, 76])

Option A. Error
Option B. Either 10.4, 56.99 or 76
Option C. Any number other than 10.4, 56.99 and 76
Option D. 56.99 only
True Answer B

Explanation :
The function random.choice(a,b,c,d) returns a random number which is selected from a, b, c and d. The output can be either a, b, c or d. Hence the output of the snippet of code shown above can be either 10.4, 56.99 or 76.

What will be the output of the following Python code?

import random

random.choice([10.4, 56.99, 76])

Question No# : 13 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# : 14 out of 20



To obtain a list of all the functions defined under sys module, which of the following functions can be used?

Option A. print(sys)
Option B. print(dir.sys)
Option C. print(dir[sys])
Option D. print(dir(sys))
True Answer D

Explanation :
The function print(dir(sys)) helps us to obtain a list of all the functions defined under the sys module. The function can be used to obtain the list of functions under any given module in Python.

To obtain a list of all the functions defined under sys module, which of the following functions can be used?

Question No# : 15 out of 20



The function random.randint(4) can return only one of the following values. Which?

Option A. 4
Option B. 3.4
Option C. error
Option D. 5
True Answer C

Explanation :
Error, the function takes two arguments.

The function random.randint(4) can return only one of the following values. Which?

Question No# : 16 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# : 17 out of 20



What will be the output of the following Python function (random module has already been imported)?

random.choice('sun')

Option A. sun
Option B. u
Option C. either s, u or n
Option D. error
True Answer C

Explanation :
The above function works with alphabets just as it does with numbers. The output of this expression will be either s, u or n.

What will be the output of the following Python function (random module has already been imported)?

random.choice('sun')

Question No# : 18 out of 20



What will be the output of the following Python code?

import datetime

  d=datetime.date(2017,06,18) 

print(d)

Option A. Error
Option B. 2017-06-18
Option C. 18-06-2017
Option D. 06-18-2017
True Answer A

Explanation :
The code shown above will result in an error because of the format of the date entered. Had the date been entered as: d=datetime.date(2017,6,18), no error would have been thrown.

What will be the output of the following Python code?

import datetime

  d=datetime.date(2017,06,18) 

print(d)

Question No# : 19 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# : 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