0

我对学习 python 非常陌生,并且正在尝试实例化我刚刚编写的第一个类的对象。

我的python类代码如下:

class Staff:
    def _init_(self, pPosition, pName, pPay):
        self.position = pPosition
        self.name = pName
        self.pay = pPay
        print("Creating Staff object.")

    def _str_(self):

        return "Position = %s, Name = %s, Pay = %d" %(self.position, self.name, self.pay)

    def calculatePay(self):

        prompt = "Enter number of hours worked for %s" %(self.name)

        hours = input(prompt)

        promt = "Enter the hourly rate for %s" %(self.name)

        hourlyRate = input(prompt)

        self.pay = int(hours)*int(hourlyRate)

        return self.pay

现在我正在尝试通过使用以下代码从 IDLE Python shell 的文本编辑器中的“运行模块”选项卡运行文件来实例化它:

officeStaff1 = Staff('Basic', 'Yvonne', 0)

但是,在它之后按 enter 时出现以下错误:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    officeStaff1 = Staff('Basic', 'Yvonne', 0)
TypeError: Staff() takes no arguments

您能向我解释一下我在这里做错了什么以及需要进行哪些更正才能使代码可行?

最好的问候, 迪比亚尔卡

4

0 回答 0