Instance variable : Name
Roll_Number
Methods : Getdata() – to input roll no. and name
: Printdata() – to diplay roll no. and name
Instance variable : Marks in 5 subjects
Methods : Inputdata() – To call Getdata and input the marks of 5 Subjects.
Outdata()-To call Printdata in order to display the marks in 5 subjects
In [4]:
class student(object):
'''Class to define a student object with the following attributes:
-Name
-Roll_Number
Methods:
-Getdata(): To input data
-Printdata(): To display data'''
def __init__(self):
self.Name = ''
self.Roll_Number = None
def Getdata(self):
self.Name = raw_input('Enter Name: ')
self.Roll_Number = int(raw_input('Enter roll no: '))
def Printdata(self):
print 'Name: '+self.Name + '\n' + 'Roll No: ' + self.Roll_Number
class marks(student):
'''Class to store marks of a student in 5 subjects'''
def __init__(self):
super(marks,self).__init__()
self.marks = []
def Inputdata(self):
self.Getdata()
for i in xrange(5):
self.marks.append(int(raw_input('Enter marks for %d subject: '%i)))
def Outdata(self):
self.Printdata()
for i in xrange(5):
print 'Marks in %d subject: '%i + str(self.marks[i])
In [2]:
m = marks()
m.Inputdata()
In [ ]: