我希望有一个程序可以让用户创建一个帐户,如果他们没有帐户,但如果他们这样做,就让他们登录并检查用户名和密码与他们制作的用户名和密码一个帐户。 此代码适用于注册,但不适用于登录部分/检查人员是否已经开户。
import os.path
if os.path.exists("username"):
login()
else:
make_account()
def make_account
filename = ("username");
with open (filename, "w") as f:
f.write (input("Enter a username: "));
filename = ("password");
with open (filename, "w") as f:
f.write (input("Enter a password: "));
def login
username = input("Enter your username: ")
password = input("Enter your password: ")
check()
def check
if username == open("username").read(): and
passsword == open("password").read():
print("Successful login")
else:
print('Incorrect')
答案 0 :(得分:0)
试试这个:
import os.path
if os.path.exists("username"):
login()
else:
make_account()
def make_account():
filename = ("username");
with open (filename, "w") as f:
f.write (input("Enter a username: "));
filename = ("password");
with open (filename, "w") as f:
f.write (input("Enter a password: "));
def login():
username = input("Enter your username: ")
password = input("Enter your password: ")
check()
def check():
if username == open("username").read() and passsword == open("password").read():
print("Successful login")
else:
print('Incorrect')