Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,025 questions

51,979 answers

573 users

How to store employee details using class in Python

1 Answer

0 votes
class Employee:
    count=0
    def __init__(self, name, language, salary):
        self.name = name
        self.language = language
        self.salary = salary
        Employee.count+=1
    def totalEmployees(self):
        print("There are %d employees" % Employee.count)
    def printDetails(self):
        print("Name:", self.name, ", Language:", self.language, ", Salary:", self.salary)

e1 = Employee("aaa", "python", 97000)
e2 = Employee("ccc", "c", 85000)
e3 = Employee("fff", "c++", 100000)
e4 = Employee("ggg", "python", 120000)
e5 = Employee("ppp", "java", 170000)

e5.totalEmployees()

e1.printDetails()
e2.printDetails()
e3.printDetails()
e4.printDetails()
e5.printDetails()




'''
run:

There are 5 employees
Name: aaa , Language: python , Salary: 97000
Name: ccc , Language: c , Salary: 85000
Name: fff , Language: c++ , Salary: 100000
Name: ggg , Language: python , Salary: 120000
Name: ppp , Language: java , Salary: 170000

'''

 



answered Oct 5, 2021 by avibootz

Related questions

1 answer 390 views
1 answer 157 views
1 answer 159 views
1 answer 225 views
...