为什么我的register函数不能在Python中工作

为什么我的register函数不能在Python中工作,python,class,oop,Python,Class,Oop,非常新的Python程序员,我的第一个OOP项目。我开了一个银行账户。大胆,我知道。以下是我目前的代码: def __init__(self, balance, username, password): """ Making the actual bank account :) """ self.money = balance def registerUsername(self, us

非常新的Python程序员,我的第一个OOP项目。我开了一个银行账户。大胆,我知道。以下是我目前的代码:


    def __init__(self, balance, username, password):
        """ Making the actual bank account :) """
        self.money = balance

    def registerUsername(self, username):
        self.username = username
        self.username = input("What is your username? ")

    def registerPassword(self, password):
        self.password = password
        self.password = input("What is your password? ")

    def login(self, attemptedUsername, attemptedPassword):
        self.attemptedUsername = attemptedUsername
        self.attemptedPassword = attemptedPassword
        if self.attemptedUsername == self.username and self.attemptedPassword == self.password:
            print("Success! You have been logged in! ")
        elif self.attemptedUsername != self.username and self.attemptedPassword != self.password:
            print('None of the fields entered are correct. Please try again! ')
        elif self.attemptedUsername == self.username and self.attemptedPassword != self.password:
            print("Your password is incorrect. Please try again! ")
        elif self.attemptedUsername != self.username and self.attemptedPassword == self.password:
            print("Your username is incorrect. Please try again! ")

    def deposit(self, amount):
        """ Deposit money using this function! """
        self.money += amount
        return self.money

    def withdraw(self, amount):
        """ Withdraw money using this method! """
        self.money -= amount
        return self.money

    def getbalance(self):
        """ Returns the amount of money you have in your account """
        return self.money

所以,我的寄存器函数不断中断。密码和用户名。当我使用它时,它要求我在写我的用户和密码之前先写一个
Self:BankAccount
参数。请帮忙

编辑:

这是我的问题。我附上了一张照片


如您所见,它让我在编写实际用户名之前输入一个self参数。我不想在username之前输入任何参数,有没有办法消除self?

registerUsername和registerPassword看起来都需要两次用户名和密码。有很多方法可以解释代码和试图做什么。如果你发布更多的问题,那么我可以进一步帮助你

编辑: 感谢您上传您尝试的图像

图像中的最后一行,替换为:

account = BankAccount(1000, 'Adam', 'Password')
这将调用
\uuuu init\uuuu
函数并创建一个1000美元的银行帐户,用户名为Adam,密码为password。接下来,添加以下行:

account.withdraw(250)
print(account.getbalance())
这将从余额中取出250美元,然后打印帐户的当前余额,现在是750美元

我们所做的是创建一个BankAccount对象并将其存储到
account
变量中。如果我们想创建另一个BankAccount对象,我们可以,这两个帐户将是分开的。例如:

account_one = BankAccount(1000, 'Adam', 'Password')
account_two = BankAccount(1000, 'Ben', 'AnotherPassword')

account_one.withdraw(250)
print(account_one.getbalance())

account_two.deposit(500)
print(account_two.getbalance())

# Account One has $750. Account Two has $1500

希望这有帮助。请继续。

忘了提及,我是在网上找到这段代码的。只是做一些调整!“大胆,我知道”-不,没有大胆。你可以去掉那一行,它对你的问题没有任何帮助。我没有家庭作业问题,它是一种自学型的东西。你可能有不和吗?我们可以在那里连接。我不明白你的意思