Python Week 8 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.


1. In python, a class is created by ____ keyword, and to create ____ of the class, we will have to use constructor of class.

·         def, file

·         class, object

·         self, .py file

·         None of these

Ans: class, object

Reason:  We start the class definition with the class keyword followed by the constructor of class.

2. What will be the output of the following python code?

class Roll:

    def __init__(self, id):

        self.id = id

        id = 231

        return id

 

val = Roll(321)

print (val.id)

·         TypeError

·         231

·         321

·         None of these

Ans: TypeError

Reason:  _init_ should return none.

 

3.  What will be the output of following python code?

class X:

    def __init__(self):

         self.a = 10

         self._b = 20

         self.b = 20

    def getB(self):

         return self.b

 

x = X()

x._b = 60

print(x.getB())

·         20

·         60

·         Error

·         Program runs but does not print anything

Ans: 20

Reason: at last self ._b=20  and def getB(self) Print(x.getB())

4. Private method in python starts with ____ while protected methods starts with ____ .

·         #, @

·         double underscore, single underscore

·         single underscore,double underscore

·         None of these

Ans: double underscore, single underscore

Reason: A double underscore prefixed to a variable makes it private.

5. What will be the output of the following code. Code is saved in a file named 'code.py' :

f = open('file.txt')

f.readlines()

print(f.name)

print ( f.closed )

f.close()

print ( f.closed )

1.Error in code

2.true

     false

     true

3.code.py

     False

     True

4.file.txt

     False

     True

Ans: Error in code

Reason: Because ‘file.text’ doesn’t in system database.