我不知道為什么,但它正在猜測(cè)密碼,但當(dāng)它猜測(cè)正確時(shí),它并沒有結(jié)束程序。任何幫助深表感謝!#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貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
嘗試更換
pass1 = input("Please insert your phone password:")
和
pass1 = int(input("Please insert your phone password:")) # turns pass1 into an integer

蠱毒傳說
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是一個(gè)更好的版本(沒有雙 while 循環(huán)并帶有 int 轉(zhuǎn)換):
#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")
添加回答
舉報(bào)
0/150
提交
取消