gpt4 book ai didi

python - 如何正确使用登录系统

转载 作者:太空宇宙 更新时间:2023-11-03 21:45:09 24 4
gpt4 key购买 nike

我找到了登录功能,但是如何检查登录是否已完成?这是我的代码:

def login():
username = input("Please enter your username")
password = input("Please enter your password")
for line in open("accounts.txt","r").readlines(): # Read the lines
login_info = line.split() # Split on the space, and store the results in a list of two strings
if username == login_info[0] and password == login_info[1]:
print("Correct credentials!")
return True
print("Incorrect credentials.")
return False

while login() == False:
login()

最佳答案

def login():
username = input("Please enter your username")
password = input("Please enter your password")
for line in open("accounts.txt","r").readlines(): # Read the lines
login_info = line.split() # Split on the space, and store the results in a list of two strings
if username == login_info[0] and password == login_info[1]:
print("Correct credentials!")
return True
print("Incorrect credentials.")
return False

while login() == False:
login()
else:
print("Your in")

在 while 循环中使用 else 语句

关于python - 如何正确使用登录系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52555720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com