我不知道為什么,但它正在猜測密碼,但當它猜測正確時,它并沒有結束程序。任何幫助深表感謝!#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
提交
取消