How do you Define and Call an object

Class Salesman has 3 attributes: salesman, sales_id, and years_worked.
I would like to define bonus, using the years_worked. I want to add “$” for each year worked.
How do I def bonus()?

The following gives me this error: <function Salesman.bonus at 0x000002602DCAF9C0>

    class Salesman:
        def __init__ (self, salesman, sales_id, years_worked):
            self.salesman = salesman  
            self.sales_id = sales_id
            self.years_worked = years_worked
        def __str__(self):
            print_me =  'nSalesman: ' + str(self.salesman)
            print_me += 'nSales ID: ' + str(self.sales_id)
            print_me += 'nAnniversary: ' + str(self.years_worked) + "years"
            return print_me
        def bonus():
            bonus = "$" * self.years_worked
            print(salesman, 'earned ', bonus, 'so far this year!')
    def main():
        print("nWe would like to Congratulate the following Employees", end = " ")
        print("who have hit their workiversary")
        salesman1 = Salesman("Frank", 1234, 10)
        salesman2 = Salesman("Justin", 5678, 5)
        print(salesman1)
        print(salesman2)
        print()salesman1_bonus = Salesman.bonus("Frank", 10)
        print(salesman1_bonus)

New contributor

User1234 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

3

Specifically, you need to make sure that the bonus method has the correct parameters and is called on an instance of the Salesman class. Here’s how you can do it:

class Salesman:
    def __init__(self, salesman, sales_id, years_worked):
        self.salesman = salesman  
        self.sales_id = sales_id
        self.years_worked = years_worked
        
    def __str__(self):
        print_me =  'nSalesman: ' + str(self.salesman)
        print_me += 'nSales ID: ' + str(self.sales_id)
        print_me += 'nAnniversary: ' + str(self.years_worked) + " years"
        return print_me
        
    def bonus(self):
        bonus = "$" * self.years_worked
        return f"{self.salesman} earned {bonus} so far this year!"

def main():
    print("nWe would like to Congratulate the following Employees", end=" ")
    print("who have hit their workiversary:")
    
    salesman1 = Salesman("Frank", 1234, 10)
    salesman2 = Salesman("Justin", 5678, 5)
    
    print(salesman1)
    print(salesman2)
    
    salesman1_bonus = salesman1.bonus()
    salesman2_bonus = salesman2.bonus()
    
    print(salesman1_bonus)
    print(salesman2_bonus)

if __name__ == "__main__":
    main()
  1. Add the self parameter to the bonus method so that it can access the instance attributes.
  2. Call the bonus method on the instances of the Salesman class, not on the class itself.
  3. Print the bonus inside the method and return the value if you want to use it later.

Let’s say we define an object called my_remote, then we give method/s to the object(my_remote)like:power_off, power_on, ok, and other methods.If we want to call the method power_off, then, we must write like this:
power_off()
or if we want to do activities, we could also write like this:
my_remote.power_off()

————————-//////——————————–

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật