0

am a python beginner, receeently started learning about classesand i wrote this got this little code that keeps bringing this error . please i need someone here to help debug it:

class employee():
`   empcount=0`
    def _init_(self,name,salary):
        self.name=name
        self.salary=salary
        employee.empcount=+1
    def displaycount(self):
        print 'Total employee: %d' %employee.empcount
    def displayemployee(self):
        print 'Name:',self.name,'salary:',self.salary
#########################################################
#main program
emp1n=raw_input('enter name of employee1:')
emp2n=raw_input('enter name of employee2:')
emp1s=input('enter salary of employee1:')
emp1n=input('enter salary of employee2:')
emp1=employee(emp1n,emp1s)
emp2=employee(emp2n,emp2s)
emp1.displayemployee()
emp2.displayepmloyee()
print 'total employees:',employee.empcount
2
Contributors
4
Replies
19
Views
4 Years
Discussion Span
Last Post by dreking6
1

double underscore in init
Several typos.

class employee():
    empcount=0
    def __init__(self,name,salary):
        self.name=name
        self.salary=salary
        employee.empcount+=1
    def displaycount(self):
        print 'Total employee: %d' %employee.empcount
    def displayemployee(self):
        print 'Name:',self.name,'salary:',self.salary
#########################################################
#main program
emp1n=raw_input('enter name of employee1:')
emp2n=raw_input('enter name of employee2:')
emp1s=input('enter salary of employee1:')
emp2s=input('enter salary of employee2:')
emp1=employee(emp1n,emp1s)
emp2=employee(emp2n,emp2s)
emp1.displayemployee()
emp2.displayemployee()
print 'total employees:',employee.empcount

Edited by slate

0

thanks for your help, i just got the answer, ill really enjoying this forum

0

You are welcome.
I would advice you not to write so much code without testing until you are more experienced.
If you have written the class only with the constructor and tested it, much of the problems were clear at the beginning.

class employee():
    def __init__(self,name,salary):
        self.name=name
        self.salary=salary
#########################################################
#main program
emp1=employee('a',10)
emp2=employee('b',20)
print emp1.name, emp2.name
print emp1.salary, emp2.salary
0

OK..I the major problem was with the underscore ..ill try to run programs in bits next time

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.