亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的代碼的一部分無法在 while 循環中工作

我的代碼的一部分無法在 while 循環中工作

蝴蝶刀刀 2023-12-12 15:11:19
我不知道為什么,但它正在猜測密碼,但當它猜測正確時,它并沒有結束程序。任何幫助深表感謝!#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


查看完整回答
反對 回復 2023-12-12
?
蠱毒傳說

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")


查看完整回答
反對 回復 2023-12-12
  • 2 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號