class UserBiz():
#定义一个登录方法
def __init__(self,id,password):
self.id=id
self.password=password
pass
def login(self):
if self.id == "":
return False
elif self.password == "":
return False
else:
if self.id ==123 and self.password==123:
return True
else:
return False
if __name__=="__main__":
times=3
while True:
print("您有%i次机会"%times)
print("-"*30)
id=input("请输入账号")
password=input("请输入密码")
obj1=UserBiz(id,password)
res=bool(obj1.login)
print(res)
if times>0:
if res is False:
times=times-1
input()
continue
else:
res is True
print("登录成功")
break
else:
break
if times==0:
print("剩余0次机会")
没调用方法么,写错了吧,你把 bool(obj1.login) 改成 obj1.login(),这么来调用 login 方法,再说获得其返回值!!