Infytq - Python

page 1 out of 4

page 1 out of 4


Question 1     

What is the output of the following code?

class Student:
	def __init__(self,name,id):
		self.name=name
		self.id=id
		print(self.id)
std=Student("Infytq",1)
std.id=2
print(std.id)





Question 2     

Which of the following is correct?

class A:
    def __init__(self,name):
        self.name=name
a1=A("Inquisitive")
a2=A("Inquisitive")





Question 3     

What is the output of the following code?

class stud:
  def __init__(self, roll_no, grade):
    self.roll_no = roll_no
    self.grade = grade
  def display (self):
    print("Roll no : ", self.roll_no, ", Grade: ", self.grade)
stud1 = stud(28, 'acode')
stud1.age=None
print(hasattr(stud1, 'age'))






Question 4     

Which of the following is correct?

class A:
	def __init__(self):
		self.count=123
		self.count=count+20
a=A()
print(a.count)





Question 5     

What is the output of the following code?

key = 100
try:
     key = key/0
except ZeroDivisionError:
     print('Error ', end = '')
else:
     print('Division successful ', end = '')
try:
    key = key/5
except:
    print('Error 1 ', end = '')
else:
    print('No Error', end = '')





Question 6     

What is the output of the following code?

class Vehicle(): 
    def_init_(self, color):
        self.color=color
class FourWheeler(Vehicle):
    def_init_(self, no_of_gears, color): 
        super(). init (color) 
        self.no_of_gears=no_of_gears
class Two Wheeler( Vehicle):
    def __init__ (self, engine_cc): 
        super().__init__("Red") 
        self.engine_cc=engine_cc
        self.color="Blue"
maruti=FourWheeler(4, "Red") 
print (maruti.color, maruti.no_of_gears) 
active=TwoWheeler(80) 
print(active.color, active.engine_cc)





Question 7     

Choose the correct option with the appropriate frequencies in the following code?

class ClassOne:
    __var_one=1001
    def __init__(self,var_two):
        self.__var_one=var_two
        self.__var_five=5
    def method_one(self):
        var_four=50
    self.__var_five=ClassOne.__var_one+self.__var_two+var_four





Question 8     

What is the status of myqueue and myqueue2 after execution of following code?

my_queue1 = Queue(3) 
my_queue2 = Queue(3) 
for index in range (0, 3) : 
    my_queuel.enqueue(index *3) 
for index in range(0, 3) : 
    if(index == 2) : 
        break 
    my_queue.enqueue(my_queue.dequeue())
my_queue2.enqueue(12)
# Assume Queue class and methods exists





Question 9     

Consider the below inputs:

input_linked_list(Head to Tail): 1->2->5->3
input_stack(Top to Bottom): 4,2,5,10
What will be the content of input_linked_list from head to tail and input_stack from top to bottom after the execution of the function genereate.
Assumption: Stack and LinkedList Classes, with the necessary methods, are available


def generate(input_linked_list):
	temp = input_linked_list.get_head()
	#get_head() returns the head node
	element = 0
	while(temp.get_next() is not None):
		#get_next() returns the address of the next node
		temp.set_data(temp.get_data()+temp.get_next().get_data()+element)
		#get_data() returns the data stored in the node
		if temp.get_data()%2 != 0:
			temp.set_data(temp.get_data+input_stact.pop())
			#set_data(data) updates the data stored in the node
			element = temp.get_data()
		else:
			input_stact.push(element)
			element = temp.get_next().get_data()
		temp = temp.get_next()
	temp.set_data(temp.get_data()+input_stact.pop())





Question 10     

Which among the below options if written at #Line 1, prints the rhyme correctly?
Expected output for your reference: 
Johnny Johnny...,
Yes Papa. 
Eating Sugar..., 
No Papa.
Telling Lies..., 
No papa.
Open your mouth..., Ha. Ha. Ha.

class ClassA:
 
    def first_method(self):
        print(“Johnny Johnny..., “) 
    def second_method(self):
        print(“Yes Papaa. “) 
    def third_method(sell:
        print(“Eating Sugar..., “) 
class CIassB(cIassA):
    def second_method(self): 
        super().first_method() 
        super().second_method() 
        super().third_method() 
        print(“No Papa. “)
    def first_method(self):
        print(“Open your mouth... , Ha. Ha. Ha. “) 
    def second_method(self):
        print(“No Papa. “) 
    def third_method(sell:
        super().second_method() 
        super().third_method() 
        self.second method()
obj_A=CIassA() 
obj_B=CIassB() 
obj_C=CIassC()




page 1 out of 4

page 1 out of 4


Sign Up Page

Oops!!

To view the solution need to Login



Score : 0 / 0
L
o
a
d
i
n
g
.
.
.