Python Week 6 Quiz Answers



Disclaimer for Pruto-ai

If you require any more information or you have any problem regarding Copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at contact@prutor-ai.com.

All the information on this website is published in good faith and for general information and educational purpose only. Prutor-ai does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website (Prutor-ai.blogspot.com), is strictly at your own risk. will not be liable for any losses and/or damages in connection with the use of our website.

In this students get weekly assignments that they have to complete every week. Here we will show you or give you all the answers for the python quiz, These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers.

Q1. Naming convention of a module of a python file is ?

·       All names should be lower case.

·       Underscore can be used.

·       Should be short

·       All of the above.

Ans- All of the above

Reasons: Naming convention of a module should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.

 

Q2. The following code is saved in a file hello.py (using python 3.X version):

def print_hello():

print ("Hello")

 

Now consider the following interaction on Python console, assuming hello.py

is in the current directory where the console is invoked:

 

>>> import hello

>>> hello.print_hello()

What will be the output of the code ?

Ans- "Hello" will be printed (without quotes)

Reason: Import is used in code it is used to import hello.py program with our environment. Then hello.print_hello() execute the print_hello() function and print Hello as output so 2nd option is correct.

 

Q3. 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):

         return 0

obj=hello()

print( obj.display() )

Ans- 0

Reason: Constructor set the value of variable as a given string then print(obj.display()) call and display method execute and return 0. So 0 will be printed as output.

 

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

Ans- Executes normally and doesn’t display anything

Reason: obj=test() will create an object and the constructor  _int_  initialise x to blank string, after display method called in next line and it prints the blank string as output.

 

Q5. What does Instantiation mean in terms of Object Oriented Programming?

·       Deleting an instance of class

·       Creating an instance of class

·       Copying an instance of class

·       Modifying an instance of class

 Ans- Creating an instance of class

Reason: instantiation means creating an instance or object oriented program. So 2nd option is correct.