DEV Community

Shivani tiwari
Shivani tiwari

Posted on

4 1

Write a program by creating an 'Employee' class having the following methods and print the final salary.

this is also a question part

1 - 'getInfo()' which takes the salary, number of hours of work per day of employee as parameter

2 - 'AddSal()' which adds 10 to salary of the employee if it is less than 500.

3 - 'AddWork()' which adds 5 to salary of employee if the number of hours of work per day is more than 6 hours.

Hello Everyone đź‘‹

You must be seeing the above question. So here we discuss the problem

There is some few step which we hove do it-

  1. First we will create a Employee class

  2. Create a 3 methods which is mention the about question

. First method getInfo()
. Second method AddSal()
. third method AddWork()

  1. here we create one more method that is final salary() which give use the employee salary

Here is the Ans of this Problem

class Employee:

    def __init__(self,name):
        self.name=name

    def getInfo(self,salary,hours):
        self.salary=salary
        self.hours=hours

    def AddSal(self):
        if self.salary<500:
            self.salary+=10
            return self.salary
    def AddWork(self):
        if self.hours>6:
            self.salary+=5
            return self.salary

    def print_final_salary(self):

        print(self.name,self.salary)


name=str(input("enter name:"))
salary=int(input("Enter Salary:"))
hours=float(input("enter hours:"))

emp=Employee(name)
emp.getInfo(salary,hours)
emp.AddSal()
emp.AddWork()
emp.print_final_salary()
Enter fullscreen mode Exit fullscreen mode

I hope you like will help you for your DSA interview preparation

Thank You
Shivani Tiwari

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay