我尝试过很多不同的投影,但他们都说打印“无效”。如果有人能解释或编辑我的代码以便我能理解,我将不胜感激。
username = []
password = []
def account_creation():
account = input("Would you like to make an Account? Yes or No: ")
if account == "Yes" or "yes":
username = input("Please make a Username: ")
password = input("Please make a Password: ")
else:
return
account_creation()
def login():
account = input("Do you have an Account? Yes or No: ")
if account == "Yes":
login_username = input("Plese enter your username: ")
login_password = input("Plese enter your password: ")
else:
return
if login_username and login_password == username and password:
print("Welcome back")
else:
print("Invalid Username or Password")
login()
答案 0 :(得分:1)
您需要先检查用户名 - 密码检查行(如_venky所述):
...
if login_username == username and login_password == password:
...
但是你在这里缺少一些更重要的东西。
您正在尝试更改函数内的全局变量,因此您需要在函数体中使用global
关键字和相关变量。
def account_creation():
global username,password
account = ... the rest of the code