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 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# : 01 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# : 02 out of 20



Which of the following functions is not defined under the sys module?

Option A. sys.platform
Option B. sys.path
Option C. sys.readline
Option D. sys.argv
True Answer C

Explanation :
The functions sys.platform, sys.path and sys.argv are defined under the sys module. The function sys.readline is not defined. However, sys.stdin.readline is defined.

Which of the following functions is not defined under the sys module?

Question No# : 03 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# : 04 out of 20



What will be the output of the following Python code?

import sys

eval(sys.stdin.readline()) 

"India"

Option A. India5
Option B. India
Option C. ‘India ’
Option D. ‘India’
True Answer D

Explanation :
The function shown above evaluates the input into a string. Hence if the input entered is enclosed in double quotes, the output will be enclosed in single quotes. Therefore, the output of this code is ‘India’.

What will be the output of the following Python code?

import sys

eval(sys.stdin.readline()) 

"India"

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



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

Option A. print(t_day.seconds)
Option B. print(t_day.months)
Option C. print(t_day.max)
Option D. print(t_day.resolution)
True Answer B

Explanation :
The statement: print(t_day.months) will throw an error because there is no function such as t_day.months, whereas t_day.seconds, t_day.max and t_day.resolution are valid, provided that t_day is defined.

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

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



What the does random.seed(3) return?

Option A. True
Option B. None
Option C. 3
Option D. 1
True Answer B

Explanation :
The function random.seed() always returns a None.

What the does random.seed(3) return?

Question No# : 10 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# : 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 function, assuming that the random library has already been included?

random.shuffle[1,2,24]

Option A. Randomized list containing the same numbers in any order
Option B. The same list, that is [1,2,24]
Option C. A list containing any random numbers between 1 and 24
Option D. Error
True Answer D

Explanation :

The function shown above will result in an error because this is the incorrect syntax for the usage of the function shuffle(). The list should be previously declared and then passed to this function to get an output. An example of the correct syntax:

>>> l=['a','b','c','d']

>>> random.shuffle(l) 

>>> print(l)

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

random.shuffle[1,2,24]

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



What does random.shuffle(x) do when x = [1, 2, 3]?

Option A. error
Option B. do nothing, it is a placeholder for a function that is yet to be implemented
Option C. shuffle the elements of the list in-place
Option D. none of the mentioned
True Answer C

Explanation :
The elements of the list passed to it are shuffled in-place.

What does random.shuffle(x) do when x = [1, 2, 3]?

Question No# : 15 out of 20



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



What will be the output of the following Python code?

random.randrange(1,100,10)

Option A. 32
Option B. 67
Option C. 91
Option D. 80
True Answer C

Explanation :
The output of this function can be any value which is a multiple of 10, plus 1. Hence a value like 11, 21, 31, 41…91 can be the output. Also, the value should necessarily be between 1 and 100. The only option which satisfies this criteria is 91.

What will be the output of the following Python code?

random.randrange(1,100,10)

Question No# : 19 out of 20



Which of the following will not be returned by random.choice(“1 ,”)?

Option A. 1
Option B. (space)
Option C. ,
Option D. none of the mentioned
True Answer D

Explanation :
Any of the characters present in the string may be returned.

Which of the following will not be returned by random.choice(“1 ,”)?

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