#Word Jumble Game
import random
import string
def jumbled():
words = ['Jumble', 'Star']#, 'Candy', 'Wings', 'Power', 'String', 'Shopping', 'Blonde', 'Steak', 'Speakers', 'Case', 'Stubborn', 'Cat', 'Marker', 'Elevator', 'Taxi', 'Eight', 'Tomato', 'Penguin', 'Custard']
count = 0
loop = True
loop2 = True
while loop:
word = string.lower(random.choice(words)
jumble = list(word)
random.shuffle(jumble)
scrambled = "".join(jumble)
while loop2:
print '\n',scrambled,'\n'
guess = raw_input('Guess the word: ')
quit = set(['quit','Quit'])
choice = 'quit'
if guess.lower() == word:
print '\nCorrect!'
count+=1
print "You took",count,"trie(s) in order to get the right answer",jumbled()
else:
print '\nTry again!\n'
count+=1
if count == 3:
if words[0]*2:
print "It looks like you're having trouble!"
print 'Your hint is: %s'(words) # I'm trying to pull a word from the above list here.
jumbled()
所以我在这里,玩我编程的游戏,从列表中选择一个随机单词,混合它然后我必须正确猜测它。这个过程有效,如果我弄错了,我会收到一条消息说再试一次,如果正确,将祝贺我,然后进入下一个单词!
我遇到的一个问题是,如果用户在 3 次后猜错了,我希望能够给出提示。但是,如果程序给我,说“混杂”作为我必须猜测的一个词,我猜错了 3 次,我想要一个基于该词的提示。我无法得到星星这个词,然后是与混乱有关的提示,可以吗?
使用我现在拥有的代码(我已经评论了我遇到问题的行),我收到一条错误消息,指出该字符串不可调用,我不知道该调用什么......
请帮忙!
如果不是太麻烦,我还需要能够输入退出然后游戏会自动退出,不幸的是,我不知道该怎么做。
提前致谢!