2017-04-11 50 views
-6
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 emp1 = Employee("zara" , 2000) emp2 = Employee("manni" , 3000) emp1.displayEmployee() emp2.displayEmployee() 
+4

請修復您的格式。這是不可讀的。然後發佈* full *錯誤消息和追蹤。 –

+0

@ PM2Ring我不認爲'我的編輯並沒有真正改善',我想OP希望使用'Code Sample'而不是'Blockquote',我不想修復縮進問題,我會喜歡讓op的意圖更加明顯,這就是爲什麼我將'Blockquote'更改爲'Code Sample'。 – McGrady

回答

1

這是你的代碼應該如何格式化:

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 


emp1 = Employee("zara", 2000) 
emp2 = Employee("manni", 3000) 
emp1.displayEmployee() 
emp2.displayEmployee() 

現在一切正常,你所做的唯一錯誤根據PEP8風格指南

不寫