CBSE computer and communication technology

Sponsor Area

Question
CBSEENCO12011678

How is __init__() different from __del__() ?

Solution

__init__() is the class constructor or initialization method which is automatically invoked when we create a new instance of a class.

__del__() is a destructor which is automatically invoked when an object (instance) goes out of scope.

For Example:

class Sample:
	def __init__(self):
		self.data = 79
		print('Data:',self.data,'created')
	def __del__(self):
		print('Data:',self.data,'deleted')
s = Sample()
del s

Sponsor Area

Question
CBSEENCO12011679

Name the function/method required to

  1. check if a string contains only uppercase letters
  2. gives the total length of the list.

Solution

Required Function

  1. isupper()
  2. len()

Question
CBSEENCO12011680

Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.

def Tot(Number) #Method to find Total
	Sum=0
	for C in Range (1, Number+1):
		Sum+=C
		RETURN Sum
print Tot[3] #Function Calls
print Tot[6]

Solution

def Tot(Number): #Method to find Total #Error 1
    Sum=0
    for C in range (1, Number+1):      #Error 2
        Sum+=C
    return Sum                         #Error 3
print Tot(3)   #Function Call          #Error 4
print Tot(6)                           #Error 4

Question
CBSEENCO12011681

Find and write the output of the following python code :

for Name in ['Jayes', 'Ramya', 'Taruna','Suraj']:
	print Name
	if Name[0]== 'T':
		break
	else :
		print 'Finished!'
	print 'Got it!'

Solution

Jayes
Ramya
Taruna
Got it!

Question
CBSEENCO12011682

Find and write the output of the following python code:

class Worker :
	def_init_(self,id,name): #constructor
		self.ID=id
		self.NAME=name
	def Change (self):
		self.ID=self.ID+10
		self.NAME='Harish'
	def Display(self,ROW):
print self.ID,self.NAME,ROW
w=Worker(55,'Fardeen')
w.Display(l)
w.Change( )
w.Display(2)
print w.ID+len(w.NAME)

Solution

Output:

55 Fardeen 1
65 Harish 2
71