因此,我試圖猜出需要多少次嘗試才能猜出混淆的單詞。坦率地說,我一直堅持這麼久,因爲這個代碼根本不起作用。請幫忙。我如何計算我已經採取了多少次嘗試?
#Word Jumble Game
import random
import string
words = ['Jumble', 'Star', 'Candy', 'Wings', 'Power', 'String', 'Shopping', 'Blonde', 'Steak', 'Speakers', 'Case', 'Stubborn', 'Cat', 'Marker', 'Elevator', 'Taxi', 'Eight', 'Tomato', 'Penguin', 'Custard']
def jumbled():
word = string.lower(random.choice(words))
jumble = list(word)
random.shuffle(jumble)
scrambled = "".join(jumble)
print '\n',scrambled,'\n'
guess = raw_input('Guess the word: ')
count=0
if guess == word:
print '\n','Correct!'
else:
print '\n','Try again!','\n',jumbled()
count+=1
jumbled()
請修復您的縮進。看起來你可能想在某處使用循環 – monkut 2014-10-31 00:27:09
*「完全不起作用」*不是問題描述。你想要你的代碼做什麼?它做什麼呢? – 2014-10-31 00:28:30
使用一段時間循環 – 2014-10-31 00:32:22