我正在编写一个骰子游戏,只允许经过身份验证的用户玩,我有一个附加和创建密码到文件的方法。但我无法搜索用户输入的特定密码。我在程序部分的主要目标是创建一个“if”语句,检查计算机是否找到了特定的密码
我不熟悉使用find语句,在过去的几天里,我浏览了很多问题和示例,但都没有用——我无法理解它将如何与我的代码一起工作
def Lock_Screen():
print("Welcome")
print("Log in(1) or Sign up(2)")
User_Choice = input("")
if User_Choice == "1":
print("Input your three-digit code:")
UserInput = input(str(""))
x = open("PasswordList.txt" , "r")
x.find(Userinput)
if x.find(UserInput):
Start_Screen()
elif User_Choice == "2":
Password = random.randint(100,999)
f = open("PasswordList.txt" , "a+")
x = open("PasswordList.txt" , "r")
PasswordList = x.read()
while Password == PasswordList:
Password = random.randint(100,999)
print("This is your password: " , Password)
f = open("PasswordList.txt" , "a+")
f.write(str(Password))
f.close()
Lock_Screen()
else:
print("That was not a valid answer")
Lock_Screen()
Lock_Screen()
.find语句应该查找变量,但它只返回一条错误消息
打开的文件没有名为
find
的方法。你好像在找完成后,
with
上下文管理器负责关闭打开的文件句柄相关问题 更多 >
编程相关推荐