我不断收到相同的错误消息:
回溯(最近一次通话):文件“”,第 1 行,在
my_wallet.checkBalance(self) NameError: name 'self' 未定义
balance = 0
def intro():
global balance
balance = int(input("How much would you like to start with? No more than 200£! ")
if balance > 200:
print("I said less than 200£!")
intro()
class wallet:
def __init__(self,money,broke):
self.broke = False
self.money = balance
def checkBalance(self):
self.money = balance
print(balance)
def noCash(self):
if balance <= 0:
print("You're done! No more £££!"
self.broke = True
从异常看来,您似乎试图将my_wallet.checkBalance
传递self
作为参数调用。
尝试做my_wallet.checkBalance()
而不是my_wallet.checkBalance(self)
self
参数自动传递给python中的类方法
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句