I'm trying to apply multilevel inheritance for student DB. I have name
, rollno
, age
, marks
, total
and average
. I want the outputs to be in the form of
Abc 1 21
Abc 1 21 98 79 88
Abc 1 21 98 79 88 255 85
The error I'm facing is that i cant concatenate str and int. I can understand that the problem is due to name in str and the rest in int. Can anyone help me out?
Here are my codes
import sys
class Person:
def __init__(self, name,rollno,age):
self.name = name
self.rollno = rollno
self.age=age
def Name(self):
return self.name + ", " + self.rollno + ", "+ self.age
class Employee(Person):
def __init__(self, name,rollno,age,m1,m2,m3):
Person.__init__(self,name,rollno,age)
self.m1 = m1
self.m2 = m2
self.m3 = m3
def Getemployee(self):
return self.name +"," + self.rollno +" ,"+ self.age +" ,"+ self.m1 +" ,"+ self.m2 +", "+ self.m3
class EmployeeDetails(Employee):
def __init__(self, name,rollno,age,m1,m2,m3,total):
Employee.__init__(self,name,rollno,age,m1,m2,m3)
self.total=self.m1+self.m2+self.m3
def empl(self):
return self.name +" ,"+ self.rollno +" ,"+ self.age +", "+ self.m1 +", "+ self.m2 +" ,"+ self.m3 +" ,"+ self.total
def main():
try:
n=int(raw_input("Enter the number of employees:"))
for i in range(n):
name =raw_input("enter the name:")
rollno =raw_input("enter the rollno:")
age =raw_input("enter the age:")
m1 =raw_input("enter m1:")
m2 =raw_input("enter m2:")
m3 =raw_input("enter m3:")
total =self.m1+self.m2+self.m3
p = Person(name,rollno,age)
e = Employee(name,rollno,age,m1,m2,m3)
s= EmployeeDetails(name,rollno,age,m1,m2,m3,total)
print p.Name()
print e.Getemployee()
print s.empl()
except ValueError :
print "value in error"
if __name__=='__main__':
main()