我不知道为什么,但它正在猜测密码,但当它猜测正确时,它并没有结束程序。任何帮助深表感谢!#importsimport time, random#Welcomeprint("Welcome to Password Guess!")pass1 = input("Please insert your phone password:")#Start systemguessclock = 0start1 = 1i = 1while 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")
2 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
尝试更换
pass1 = input("Please insert your phone password:")
和
pass1 = int(input("Please insert your phone password:")) # turns pass1 into an integer
蛊毒传说
TA贡献1895条经验 获得超3个赞
这是一个更好的版本(没有双 while 循环并带有 int 转换):
#imports
import time, random
#Welcome
print("Welcome to Password Guess!")
pass1 = int(input("Please insert your phone password:"))
#Start system
guessclock = 0
start1 = 1
i = True
while i:
guess1 = random.randint(1, 2)
guessclock += 1
print(guess1)
if pass1 == guess1:
i = False
print("Password guessed")
print("It took", guessclock)
print("Attempts")
添加回答
举报
0/150
提交
取消