0
所以我的問題與我的代碼是,即使我已輸入正確的猜測詞,我的代碼仍然讀取它不正確;因此,請我再試一次。我如何擺脫這個循環?欣賞它。如何擺脫我的while循環
import random
count = 1
word = ['orange' , 'apple' , 'chicken' , 'python' , 'zynga'] #original list
randomWord = list(random.choice(word)) #defining randomWord to make sure random
choice jumbled = ""
length = len(randomWord)
for wordLoop in range(length):
randomLetter = random.choice(randomWord)
randomWord.remove(randomLetter)
jumbled = jumbled + randomLetter
print("The jumbled word is:", jumbled)
guess = input("Please enter your guess: ").strip().lower()
while guess != randomWord:
print("Try again.")
guess = input("Please enter your guess: ").strip().lower()
count += 1
if guess == randomWord:
print("You got it!")
print("Number of guesses it took to get the right answer: ", count)
break存在一個循環 – Nullman
這是一個關於for循環的問題的重複,這裏的這個問題是關於while循環的嗎?更重要的是這個問題甚至沒有關於退出while循環。它應該是「爲什麼我的條件總是評估真實」。 – shove
@shove您可以投票重新打開。閉幕審查是https://stackoverflow.com/review/close/15181216 –