Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

Write a program using class to accept three sides of a triangle and print its area?

Answer»

class Tr:

def_init_(self, a, b, c):

self.a = float(a)

self.b = float(b)

self.c = float(c)

def area(self):

s = (self.a + self.b + self.c)/2

return((s*(s-self.a) * (s-self.b) * (s-self.c) ** 0.5)

a = input(“Enter side 1:”)

b = input(“Enter side2:”)

c = input(“Enter side3:”)

ans=Tr(a,b,c)

print(ans.area( ))

Output:

Enter side 1 : 3

Enter side 2 : 4

Enter side 3 : 5

6.0

2.

The variables which are defined inside the class is by default.(a) private(b) public (c) protected(d) local

Answer»

Answer is (b) public

3.

All the string variables are of object of class .......

Answer»

All the string variables are of object of class strings

4.

Which of the following class declaration is correct?(a) class class_name(b) class class_name< >(c) class class_name:(d) class class_name[ ]

Answer»

(c) class class_name:

5.

What is instantiation?

Answer»

Once a class is created, next you should create an object or instance of that class. The process of creating object is called as “Class Instantiation”. 

Syntax:

object_name = class_name( )

6.

How will you create constructor in Python?

Answer»

In Python, there is a special function called “init” which act as a Constructor. It must begin and end with double underscore. This function will act as an ordinary function;

General format of init method (Constructor function) def_init_(self.[args …………….]):

<statements>

7.

The init function should begin and end with(a) underscore(b) double underscore(c) #(d) S

Answer»

(b) double underscore

8.

A statement in a class definition may be a ………..(a) variable declaration(b) decision control(c) loop(d) all of these

Answer»

(d) all of these

9.

The first argument of the class method is …….(a) class(b) func(c) def(d) self

Answer»

The first argument of the class method is self

10.

class is defined by the keyword ……

Answer»

class is defined by the keyword class

11.

Which of the following are the key features of an Object Oriented Programming language?(a) Constructor and Classes(b) Constructor and Object(c) Classes and Objects(d) Constructor and Destructor

Answer»

(c) Classes and Objects

12.

The statements defined inside the class must be properly indented. True / false

Answer»

The statements defined inside the class must be properly indented. True

13.

What is class?

Answer»

Classes and Objects are the key features of Object Oriented Programming. Class is the main building block in Python. Object is a collection of data and function that act on those data. Class is a template for the object. According to the concept of Object Oriented Programming, objects are also called as instances of a class or class variable

14.

Write a program using class to store name and marks of students in list and print total marks?

Answer»

class stud:

def_init_(self):

self.name= ” ”

self.m1=0

self.m2=0

self.tot=0

def gdata(self):

self.name = input(“Enter your name”)

self.m1 = int(input(“Enter marks 1”))

self.m2 = int(input(“Enter marks2”))

self, tot = self.m1+self.m2

def disp(self):

print(self.name)

print(self.m1)

print(self.m2)

print(self.tot)

mlist = [ ]

st = stud( )

st.gdata( )

mlist. append(st)

for x in mlist:

x.disp( )

Output:

Enter your name Ram

Enter marks 1 100

Enter marks2 100

Ram 100 100 200

15.

……….. is a special function to gets executed automatically when an object exit from the scope.(a) constructor(b) init(c) destructor(d) object

Answer»

(c) destructor

16.

What is the purpose of Destructor?

Answer»

Destructor is also a special method gets executed automatically when an object exit from the scope. It is just opposite to constructor. In Python, _del_( ) method is used as destructor.

17.

What are class members? How do you define it?

Answer»

In Python, a class is defined by using the keyword class. Every class has a unique name followed by a colon ( : ).

Syntax:

class class_name:

statement_1

statement_2

…………………

…………………

statement_n

Where, statement in a class definition may be a variable declaration, decision control, loop or even a function definition. Variables defined inside a class are called as “Class Variable” and functions are called as “Methods”. Class variable and methods are together known as members of the class. The class members should be accessed through objects or instance of class. A class can be defined anywhere in a Python program.

Example:

Program to define a class

class Sample:

x, y = 10, 20 # class variables

In the above code, name of the class is Sample and it has two variables x and y having the initial value 10 and 20 respectively. To access the values defined inside the class, you need an object or instance of the class.

18.

Which of the following method is automatically executed when an object is created?(a) _object_( )(b) _del( )_( ) (c) _func_( ) (d) _init_( )

Answer»

Answer (d) _init_( )

19.

Functions defined inside a class:(a) Functions(b) Module(c) Methods(d) section

Answer»

Functions defined inside a class Methods

20.

Which of the following method is used as destructor? (a) _init_( ) (b) _dest_ ( ) (c) _rem_( )(d) _del_( )

Answer»

_del_( ) is used as destructor

21.

…….. and ……. are called as members of the class

Answer»

class variables and methods are called as members of the class

22.

The process of creating an object is called as:(a) Constructor(b) Destructor(c) Initialize(d) Instantiation

Answer»

(d) Instantiation

23.

Find the correct statement from the following.(a) constructor function can be defined with arguments(b) constructor function can be defined without arguments(c) constructor function can be defined with or without argument(d) constructor function cannot be defined

Answer»

(c) constructor function can be defined with or without argument

24.

How do define constructor and destructor in Python?

Answer»

General format of init method (Constructor function) 

def_init_(self.[args ……….]):

<statements>

To define destructor

 _del_ ( ) method is used.

25.

Write a class with two private class variables and print the sum using a method?

Answer»

class Sample:

def_init_(self,n1,n2):

self._n1=n1

self._n2=n2

def display(self):

print(“class variable 1:” , self._n1)

print(“class variable 2:” , self._n2)

print(“sum self._n1 + self._n2)

s = sample(10, 20)

s.display( )

Output:

class variable 1 : 10

class variable 2 : 20

sum : 30

26.

Match the following1. constructor – (i) def process(self)2. Destructor – (ii) S.x3. method – (iii) _del_(self)4. object – (iv) _init_(self, num)(a) 1-(iv) 2-(iii) 3-(i) 4-(ii)(b) 1-(i) 2-(ii) 3-(iii) 4-(iv)(c) 1-(iv) 2-(ii) 3-(i) 4-(iii)(d) 1-(i) 2-(iii) 3-(iv) 4-(ii)

Answer»

(a) 1-(iv) 2-(iii) 3-(i) 4-(ii)

27.

Class members are accessed through which operator?(a) &amp;(b) .(c) #(d) %

Answer»

Class members are accessed through . operator

28.

Which of the following is the private class variable? (a) _num (b) ##num (c) $$num (d) &amp;&amp;num

Answer»

_num is the private class variable

29.

A private class variable is prefixed with(a) _ (b) &amp;&amp; (c) ## (d) **

Answer»

A private class variable is prefixed with -

30.

All integer variables used in python program is an object of class ………

Answer»

All integer variables used in python program is an object of class int

31.

……….. is used to initialize the class variables.(a) constructor(b) destructor(c) class(d) objects

Answer»

(a) constructor

32.

What is the output of the following program?class Greeting: def_init_(self, name): self._name = name def display(self): print(“Good Morning “ , self._name)  obj=Greeting(‘Bindu Madhavan’) obj.display( )

Answer»

class Greeting:

def_init_(self, name):

self._name = name

def display(self):

print(“Good Morning “ , self._name) 

obj=Greeting(‘Bindu Madhavan’)

obj.display( )

Output:

Bindu Madhavan Good Morning

33.

What is the output of the following program?

Answer»

class Sample:

_num=10

def disp(self):

print(self._num) 

S=Sample( )

S.disp( )

print(S._num)

Output:

Error: Sample has no attribute S._num

10

34.

Which of the following is the output of the following program?– class Student:def_init_(self, name):self.name=nameS=Student(“Tamil”)(a) Error(b) Tamil(c) name

Answer»

output :

(b) Tamil

35.

Find the error in the following program to get the given output?class Fruits:def_init_(self, f1, f2):self.f1=f1self.f2=f2def display (self):print(“Fruit 1 = %s, Fruit 2 = %s” %(self.fl, self.f2)) F = Fruits (‘Apple’ , ‘Mango’)del F.displayF.display( )

Answer»

Output

Fruit 1 = Apple, Fruit 2 = Mango

In line No. 8, del F.display will not come

36.

Write note on self?

Answer»

The class method must have the first argument named as self. No need to pass a value for this argument when we call the method. Python provides its value automatically. Even if – a method takes no arguments, it should be defined with the first argument called self. If a method is defined to accept only one argument it will take it as two arguments ie. self and the defined argument.

37.

Which variables can be accessed only within the class?(a) private(b) public(c) protected(d) local

Answer»

private variables can be accessed only within the class

38.

…………. are also called as instances of a class or class variable.

Answer»

objects are also called as instances of a class or class variable.

39.

Write the output for the program?

Answer»

class Sample:

def_init_(self, num):

print(“Constructor of class Sample…”)

self.num=num

print(“The value is num)

S=Sample(10)

Constructor of class sample…

The value is: 10

40.

Which variables can be accessed anywhere in the program using dot operator?(a) private(b) public(c) protected(d) auto

Answer»

public variables can be accessed anywhere in the program using dot operator

41.

Write a menu driven program to read, display, add and subtract two distances? 

Answer»

class Dist:

def_init_(self):

self, dist 1=0

self.dist 2=0

def read(self):

self.dist 1=int(input(“Enter distance 1”))

self.dist 2=int(input(“Enter distance 2”))

def disp(self):

print(“distance 1” , self.dist 1)

print(“distance 2” , self.dist 2)

def add(self):

print(“Total distances” , self.dist 1+self.dist 2)

def sub(self):

print(“Subtracted distance” , self.dist 1-self.dist 2) 

d=Dist( )

choi = “y”

while(choi == “y”):

print(” 1. accept \n 2. Display \n 3. Total \n 4. Subtract”)

ch = int(input(“Enter your choice”))

if(ch==l):

d.read( )

elif(ch==2):

d.disp( )

elif(ch==3):

d.add( )

elif(ch==4):

d.sub( )

else: 

print(“Invalid Input…”)

choi = input(“Do you want to continue”)

Output:

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 3

Enter distance 1 : 100

Enter distance 2 : 75

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 3

Total distances : 175

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Subtract

Enter your choice : 2

Enter distance 1 : 100

Enter distance 2 : 75

Do you want to continue .. y

1. Accept

2. Display

3. Add

4. Sub

Enter your choice : 4

Subtracted distance : 25

Do you want to continue .. N

42.

Write a menu driven program that keeps record of books available in your school library?

Answer»

class Library:

def_init_(self):

self.bookname= ””

self.author= ””

def getdata(self):

self.bookname = input(“Enter Name of the Book: “) 

self.author = input(“Enter Author of the Book: “)

def display(self):

print(“Name of the Book: “ ,self.bookname)

print(” Author of the Book: “ ,self.author)

print(“\n”)

book=[ ] #empty list

ch = ‘y’

while(ch= = ’y’):

print(“1. Add New Book \n 2.Display Books”)

resp = int(input(“Enter your choice :”))

if(resp= =1):

L=Library( )

L.getdata( )

book.append(L)

elif(resp= =2):

for x in book:

x.display( ) 

else:

print(“Invalid input….”)

ch = input(“Do you want continue….”)

Output:

1. Add New Book

2. Display Books

Enter your choice : 1

Enter Name of the Book: Programming in C++ 

Enter Author of the Book: K. Kannan

Do you want continue….y

1. Add New Book

2. Display Books

Enter your choice : 1

Enter Name of the Book: Learn Python

Enter Author of the Book: V.G.Ramakrishnan

Do you want continue….y

1. Add New Book

2. Display Books

Enter your choice : 1

Enter Name of the Book: Advanced Python

Enter Author of the Book: Dr. Vidhya

Do you want continue….y

1. Add New Book

2. Display Books Enter your choice : 1

Enter Name of the Book: Working with OpenOffice 

Enter Author of the Book: N.V.Gowrisankar

Do you want continue….y

1. Add New Book

2. Display Books

Enter your choice : 1

Enter Name of the Book: Data Structure

Enter Author of the Book: K.Lenin

Do you want continue….y

1. Add New Book

2. Display Books

Enter your choice : 1

Enter Name of the Book: An Introduction to Database System

Enter Author of the Book: R.Sreenivasan

Do you want continue….y

1. Add New Book

2. Display Books

Enter your choice : 2

Enter Name of the Book: Programming in C++ 

Enter Author of the Book: K. Kannan

Name of the Book: Learn Python

Author of the Book: V.G.Ramakrishnan

Name of the Book: Advanced Python

Author of the Book: Dr. Vidhya

Name of the Book: Working with OpenOffice 

Author of the Book: N.V.Gowrisankar

Name of the Book: Data Structure

Author of the Book: K.Lenin

Name of the Book: An Introduction to Database System

Author of the Book: R.Sreenivasan

Do you want continue….n

43.

Capital increases, if ………………. increase.(a) Expenses(b) Drawings(c) Revenue(d) Interest on drawings

Answer»

Correct option is (c) Revenue

44.

When owner brought personal payables/ creditors in business ………(a) one would increase, another would decrease.(b) asset and liability have increased by same amount.(c) capital and asset have decreased by same amount.(d) increase in capital, increase in liability.

Answer»

Correct option is (a) one would increase, another would decrease.

45.

When lending of funds ………(a) increase in one asset – decrease in another asset.(b) one would increase – another would decrease.(c) increase in capital – increase in asset.(d) increase in asset – decrease in liability.

Answer»

Correct option is (a) increase in one asset – decrease in another asset.

46.

Why did Mahatma Gandhi organise the Champaran Satyagraha in Bihar?

Answer»

Mahatma Gandhi organised the Champaran Satyagraha in order to voice against the oppressive indigo plantation system.

47.

Why did Mahatma Gandhi perceive ‘Salt’ as a powerful symbol that unite the nation?

Answer»

(i) Salt was something consumed by the rich and the poor alike and was one of the most essential food items. 

(ii) The tax on salt and the government monopoly over its production revealed the most oppressive face of the British. 

(iii) Mahatma thought that an ordinary thing like salt could give the movement a grand success which would ultimately dethrone the foreign rule.

48.

What did the peasants of Kheda demand?

Answer»

They demanded relaxation in revenue collection.

49.

Who had used the term ‘Cold War’ and why?

Answer»

The term Cold War was used by George Orwell in the context of bitter relations between the countries in modern international politics.

50.

Why did Mahatma Gandhi find in ‘salt’ a powerful symbol that could unite the nation? Explain

Answer»

Mahatma Gandhi found in ‘salt’ a powerful symbol that could unite the nation. 

On 31 January 1930, he sent a letter to the Viceroy Irwin, stating eleven demands. The most important demand was to abolish the salt tax. 

Salt is consumed by all sections of the society, by the rich and the poor alike. 

It is one of the most essential items of food. 

Mahatma Gandhi declared that tax on salt and government monopoly over its production was the most oppressive step taken by the British government. 

Mahatma Gandhi choose salt because all sections of the society could identify with it and everyone could be brought into a united struggle.