在函数内调用另一个函数时发生NameError

时间:2019-06-14 18:41:22

标签: python

为什么我收到pays_bill的名称错误?

error: NameError: name 'pays_bill' is not defined
class Customer:
    def __init__(self,total):
        self.billamt=total

    def pays_bill(self,amount):
        print("maaz  pays bill amount of Rs.",amount)

    def purchases(self):
        discount=(.05*self.billamt)
        amount=(self.billamt-discount)
        pays_bill(self,amount)

x=Customer(1000)
x.purchases()

1 个答案:

答案 0 :(得分:1)

这会很好

class Customer:
    def __init__(self,total):
        self.billamt=total

    def pays_bill(self,amount):
        print("maaz  pays bill amount of Rs.",amount)

    def purchases(self):
        discount=(.05*self.billamt)
        amount=(self.billamt-discount)
        self.pays_bill(amount)

x=Customer(1000)
x.purchases()