猿问

当我在 python 中使用 while 循环运行命令时,我遇到了数量问题

我导入了一个 json 文件并为超级大米的大米银行帐户创建了一个 while 循环。我在父代码下创建 def 但遇到错误:TypeError: withdraw_money() missing 1 required positional argument: 'amount'。我还尝试为每个子类设置新的一周新值,这些子类将为超级大米帐户和预付附加 500,为普通大米 A 附加 0。由于错误,我被 SuperRiceAccount.withdraw_money(amount) 困住了,我仍然需要找出新一周的功能。谁能帮我?


下面是我的代码


class BaseAccount:

      def __init__(self, account_id, account_type, full_name, birthday, balance,amount=500):

        self.account_id = account_id

        self.account_type = account_type

        self.full_name = full_name

        self.birthday = birthday

        self.balance = balance

        self.amount = amount


    def account_info(self):

        for p in data ['accounts']:

            print('You have successfully withdrawn 500 grams from the account.')

            print('Account ID:' + p['account_id'])

            print('Account Type:' + p['account_type'])

            print('Full Name:' + p['full_name'])

            print('Birthday:' + p['birthday'])

        print('Balance: ' + self.balance + ' left')


    def withdraw_money(self, amount):

        self.balance = self.balance - amount(500)

        for p in data['accounts']:

            print('You have successfully withdrawn 500 grams from the account.')

            print('Account ID:' + p['account_id'])

            print('Account Type:' + p['account_type'])

            print('Full Name:' + p['full_name'])

            print('Birthday:' + p['birthday'])

            print('Balance: ' + self.balance + ' left')


    def new_week(self):

        return


class SuperRiceAccount(BaseAccount):

    def __init__(self, account_id, account_type, full_name, birthday, balance):

        super().__init__(account_id, account_type, full_name, birthday, balance)

        if self.balance >= 2000:

            print ('You still have ', self.balance, ' left.')

        else:

            print('You do not have enough balance.')


    def new_week(self):

        if initial_balance < 2000:

            self.balance = self.balance + 500

            print('Your new balance is ', self.balance, ' left')



慕村225694
浏览 117回答 1
1回答

富国沪深

SuperRiceAccount调用方法时应使用对象withdraw_money。发生的情况是,当您调用该函数时,金额作为第一个参数传递,因此缺少self第二个参数。&nbsp;通过初始化修复它:amountbank&nbsp;=&nbsp;SuperRiceAccount([PASS&nbsp;HERE&nbsp;INITIALIZATION&nbsp;PARAMETERS])并致电:bank.withdraw_money(amount) bank.account_info(amount)
随时随地看视频慕课网APP

相关分类

Python
我要回答