python - 我的部分代码在 while 循环中不起作用
问题描述
我不知道为什么,但它是在猜测密码,但是当它猜对时它并没有结束程序。任何帮助深表感谢!
#imports
import time, random
#Welcome
print("Welcome to Password Guess!")
pass1 = input("Please insert your phone password:")
#Start system
guessclock = 0
start1 = 1
i = 1
while i < 2:
while i < 2:
guess1 = random.randint(1, 2)
guessclock += 1
print(guess1)
if pass1 == guess1:
i = 3
print("Password guessed")
print("It took", guessclock)
print("Attempts")
解决方案
尝试更换
pass1 = input("Please insert your phone password:")
和
pass1 = int(input("Please insert your phone password:")) # turns pass1 into an integer
推荐阅读
- reactjs - 使用 React / Redux 滑动面板 0.3 或 0.6 秒是真的吗,我们已经必须调度两个动作来处理它?
- r - R预测函数使用字符变量作为模型名称
- excel - 该任务使用什么公式?
- java - 导航到 Firestore 中的特定文档时如何显示 subСollection
- amazon-web-services - 在 Amazon Cognito 中恢复已删除的用户池
- nginx - microk8s 入口导致操作超时
- arrays - 将“喜欢”的图像保存到本地存储
- scala - Scala 中的类型不匹配与 IDEA 和 FP
- reactjs - 如何导航到不同的屏幕而不在本机反应中显示屏幕
- linux - 无法删除旧的 Docker 网络设置