【发布时间】:2021-12-22 12:54:29
【问题描述】:
我希望用户能够输入新的用户名和密码并将其保存到同一个文件中,以便用于随后的登录过程。用户应该能够在input 中输入新的用户名,密码也是如此,然后将其保存到文件中以供以后使用。我自己会这样做,但我不知道如何将它保存到同一个文件中。
import time
import sys
uun = "test"
uun01 = "test01"
uun02 = "test02"
usernames = (uun+uun01+uun02)
upw = "test"
upw01 = "test01"
upw02 = "test02"
passwords = (upw+upw01+upw02)
max_attempts = 3
attempts = 0
while True:
print("Username")
username = input("")
print("Password")
password = input("")
if username in usernames and password in passwords:
print("Access Granted")
else:
attempts+=1
if attempts >= max_attempts:
print(f"reached max attempts of {attempts} ")
sys.exit()
print("Try Again (10 sec)")
time.sleep(10)
continue
break
【问题讨论】: