AKTU PYTHON QUIZ 8

 

Python Programming Quiz 8th Week Quiz Solution 2020 | python quiz 8 solution 2020

 

Python Programming Quiz – 8th Week Quiz Solution 2020


[1] A class definition in python begins with the keyword –

(a): def , file 
(b): class , object
(c): self , py file
(d): None of these

Answer: (b) class , object

Reason:- Python is an “object-oriented programming language.” This means that almost all the code is implemented using a special construct called classes. ... This is done using the keyword “class,” which is a grouping of object-oriented constructs. By the end of this tutorial you will be able to: Define what is a class.


Q-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).

(a): TypeError
(b): 231
(c): 321
(d): None of these
https://youtu.be/w9LXF1MYRes 
please subscribe this channel for the answers of future quizes

Answer: (b): 231
Reason:- its return value id 231 because the id is already is given this code so its output of 231.


[3] What will be the output of following python code?

class X:
def __init__(self):
self.a = 10
self._b = 20
def getB(self):
return self._b

x = X()
x._b = 60
print(x.getB())

(a): 20
(b): 60
(c): Error
(d): Program runs but does not print anything


Answer: (b) 20

Reason:-  20 is  the output of following python code because this code is right .

4.private  method starts with _______ while protected method starts with ________.

(a).#,@
(b).double underscore,single underscore 
(c).single underscore , double underscore
(d).None of these

Answer:- (b).double underscore,single underscore.


Reason:- In Python, there is no existence of Private methods that cannot be accessed except inside a class. However, to define a private method prefix the member name with double underscore  ,The culture in Python is that names starting with underscores mean, "don't use these unless you really know you should." You might choose to begin your "protected" methods with underscores.

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


(a).Error in code 

(b). true
      false
       true

(c). code.py
      False
     True

(d)file.txt
     False
     True

Answer;- (d)file.txt
     False
     True

Reason:-  this is 3 function and first is file.txt and closed , named its is defined The readlines() method returns a list containing each line in the file as a list item. Use the hint parameter to limit the number of lines returned.
The close() method closes an open file. You should always close your files, in some cases, due to buffering, changes made to a file may not show until you close the file

Comments

Popular posts from this blog

COMMOM BUS SYSTEM USING MULTIPLEXER

CSS QUIZ 9 ANSWERS

HOW BASIC COMPUTER WORKS USING COMMON BUS SYSTEM