Ad Code

Python Quiz 7 Answers 100% Correct No UFM

 

Programming for Noobs

PYTHON Quiz 7 Answers




 

Disclaimer-

This article only attempts to discover some questions that can be generated in PYTHON for Engineering with the answer to all these questions. There can be some errors to these answers. If you find any error then please do write to us.

 

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

1.All names should be lower case

2.Under score can be used

3.Should be short

4.All of the above

Reason: module is a file containing python definitions and statement modules should have short ,all lowercases names ,underscores can be used in the module name

Programming for Noobs



 

.

Programming for Noobs

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?

1.hello is a keyword in python, so it will produce error

2.'Hello' will be printed (without quotes)

3.Nothing will be printed

4.We cannot import a .py file

Reason: Nothing will be printed because there is no print statement after importing the module

Programming for Noobs

 

 

 

 

Programming for Noobs

Q3. class hello:
    def __init__(self,a='Visit Prutor.ai website'):
        self.a=a
    def display(self):
        return 0
obj=hello()
print( obj.display() )

1.The program has an error because constructor can’t have default arguments

2.0

3.'Visit Prutor.ai website' is displayed

4.The program has an error because display function doesn’t have parameters

Reason:  The program gives the output is 0, the attribute of ‘hello’ object is provided by the return value 0 is assign the object ‘a’ and the program print the value 0 correct output .

Programming for Noobs

 

 

 

 

 

Programming for Noobs

Q4.   class test:
    def __init__(self,x=''):
        self.x=x
    def display(self):
        print(self.x)
obj=test()
obj.display()

1.Executes normally and doesn’t display anything

2.Displays 0, which is the automatic default value

3.Error as display function requires additional argument

4.None of the above

Reason:  The program is provided an attribute error ‘test’ object has no attribute ‘x’

So ,error as at least one argument is required while creating an object

 

Programming for Noobs



 

 

Programming for Noobs

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

1.Deleting an instance of class

2.Creating an instance of class

3.Copying an instance of class

4.Modifying an instance of class

 

Reason:  Instantiating a class is creating copy of the class ,to instantiating a class we simply call the class as if it were function , passing the argument that the _init_ method defines

Programming for Noobs

Please subscribe to our channel 







 

 

Post a Comment

0 Comments