AKTU Python Programming 7th Week Quiz Solutions


AKTU ICT Academy Python Programming a practical Approach 7th Week Quiz Solutions

Hey guys here are the solutions of AKTU ICT Academy Python quiz solutions for the first week. AKTU released noncredit courses for 2nd-year computer science students of B. Tech. The course code is KNC 301/KNC 302.


These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers. Please attempt the quiz yourself before proceeding for the answers.

Disclaimer :- I don't claim for the 100% accuracy of the answers. I tried my level best to present the correct answers and I'm not responsible if any of the answer is incorrect.


[1]   What should be the name of the python file that defines a module foo?

(a): module.py
(b): foo_module.py
(c): module_foo.py
(d): foo.py
Answer: (d) foo.py


[2] The following code is saved in a file mod.py (using python 3.X version):


def printHi():
    print ("Hi")

Now consider the following interaction on Python console, assuming mod.py 
is in the current directory where the console is invoked:

>>> import mod
>>> printHi()
Traceback
(most recent call last):  File "", line 1, in 
NameError: name 'printHi' is not defined

What is the reason for the NameError error?

(a): printHi is a keyword in Python
(b): printHi is not a valid function name
(c): We need to qualify function name with module name, as mod.printHi()
(d): import does not import files in the current directory

Answer: (c) We need to qualify function name with module name, as mod.printHi()



[3] The following code is saved in a file mod.py (using python 3.X version):



def printHi():
    print ("Hi")

Now consider the following interaction on Python console, assuming 
mod.py is in the current directory where the console is invoked:

>>> import mod
>>> print (mod.__name__)

What will be the output on the console?

(a): Hi
(b): mod.Hi
(c): mod
(d): Error since __name__ is not defined

Answer: (c) mod

[4] True or False: It is possible to import more than one modules in the same program?

(a): True
(b): False

Answer: (a) True


[5] Suppose we have a python module as file mdl.py defining four functions f1, f2, f3 and f4. Now we give following python command at the python shell:


>>> from mdl import f2
Which of the following functions from mdl.py can now be invoked from calling script -

(a): f1
(b): f2
(c): f3
(d): f4

Answer: (b) f2


[6]

A python module file mdl.py can be used as a script as well as an importable module by adding which of the following code at the end of the file mdl.py:


(A) if _ main _  == “ _ name _ “ :
         ... # suitable code
(B) if _ main _  == “ _ mdl _ “ :
         ... # suitable code
(C) if _ name _  == “ _ main _ “ :
         ... # suitable code
(D) if _ name _  == “ _ mdl _ “ :
         ... # suitable code

(a): A
(b): B
(c): C
(d): D

Answer: (c) C


[7]

Suppose we have a python module as file mdl.py defining three functions f1, f2 and f3. Now we give the following python command at the python shell:


>>> from mdl import *
Which of the following functions from mdl.py can be invoked from calling script -

(a): only f1 and f3
(b): only f2 and f3
(c): only f3 and f1
(d): all of f1, f2 and f3

Answer: (d) all of f1, f2 and f3


[8]

Suppose a python module file mdl.py contains the required code at the end of the file mdl.py so that it can be used as a script as well as an importable module. Now we can run script mdl.py by the following command at python shell:


>>> import mdl

(a): True
(b): False

Answer: (b) False


[9]

Class construct in python contains:

(a): data as attributes of objects
(b): functions as actions on data
(c): both (a) and (b)
(d): either (a) or (b)

Answer: (c) both (a) and (b)

  
[10] 

In python, class is itself an object of type: type.

(a): True
(b): False

Answer: (a) True

[11] 

What is the output of the following python code?


class hello:
     def __init__(self,a="Visit Prutor.ai website"):
         self.a=a

     def display(self):
         print(self.a)
obj=hello()
obj.display()
(a): The program has an error because constructor can’t have default arguments
(b): Nothing is displayed
(c): “Visit Prutor.ai website” is displayed
(d): The program has an error because display function doesn’t have parameters

Answer: (c) “Visit Prutor.ai website” is displayed


[12] 

What is the output of the following python code?


class test:
    def __init__(self,x):
        self.x=x
 
    def display(self):
        print(self.x)
obj=test()
obj.display()
(a): Executes normally and doesn’t display anything
(b): Displays 0, which is the automatic default value
(c): Error as at least one argument is required while creating an object
(d): Error as display function requires additional argument

Answer: (c) Error as at least one argument is required while creating an object


[13] 

What does Instantiation mean in terms of Object Oriented Programming?

(a): Deleting an instance of class
(b): Creating an instance of class
(c): Copying an instance of class
(d): Modifying an instance of class

Answer: (b) Creating an instance of class

[14] 

Select the correct alternative for special method __init__ in python -

(a): Is used to create a new object for a class
(b): Only one constructor is allowed per class
(c): Uses default arguments
(d): All of the above

Answer: (d) All of the above

[15] 

The return value of special method __str__ can be an object of any type in python.

(a): True
(b): False

Answer: (b) False

SHARE If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
Newer Posts Newer Posts Older Posts Older Posts

More posts

Comments

Post a Comment

Sponsored Content