Inheritance

Sponsor Area

Question
CBSEENCO12011588

Write two methods in python using concept of Function Overloading (Polymorphism) to perform the following operations:
(i) A function having one argument as Radius, to calculate Area of Circle as 3.14#Radius#Radius
(ii) A function having two arguments as Base and Height, to calculate Area of right-angled triangle as 0.5#Base#Height.

Solution

def Area(R):
	print 3.14*R*R
def Area(B,H):
	print 0.5*B*H

Sponsor Area

Question
CBSEENCO12011589

What will be the status of the following list after the First, Second and Third pass of the bubble sort method used for arranging the following elements in ascending order ?

Note: Show the status of all the elements after each pass very clearly underlining the changes.
52, 42, -10, 60, 90, 20

Solution

I Pass

52 42 -10 60 90 20
42 52 -10 60 90 20
42 -10 52 60 90 20
42 -10 52 60 90 20
42 -10 52 60 90 20
42 -10 52 60 20 90
 
II Pass
42 -10 52 60 20 90
-10 42 52 60 20 90
-10 42 52 60 20 90
-10 42 52 60 20 90
-10 42 52 20 60 90

III Pass
-10
42
52
20
60
90
-10
42
52
20
60
90
-10
42
52
20
60
90
-10
42
20
52
60
90

Question
CBSEENCO12011591

Write Addnew(Member) and Remove(Member) methods in python to Add a new Member and Remove a Member from a List of Members, considering them to act as INSERT and DELETE operations of the data structure Queue.

Solution

class queue:
	Member=[]
	def Addnew(self):
		a=input('enter member name: ')
		queue.Member.append(a)
	def Remove(self):
		if (queue.Member==[]):
			print 'Queue empty'
		else:
			print 'deleted element is: ',queue.Member[0]
del queue.Member[0] # queue.Member.delete()

Question
CBSEENCO12011592

Write definition of a Method MSEARCH(STATES) to display all the state names from a list of STATES, which are starting with alphabet M.
For example:
If the list STATES contains
['MP','UP','WB','TN','MH','MZ','DL','BH','RJ','HR']
The following should get displayed
MP
MH
MZ

Solution

def MSEARCH(STATES):
	for i in STATES:
		if i[0]=='M':
			print i