给出提示的问题

我有一个简单的单词混杂游戏.我已经做过混乱了,但是现在我想添加一个“提示”系统.我不知道如何显示元组中的一项.我有2个元组,我想根据第一个元组是什么从第二个元组中拉出.我有一个WORD =(“ x”,“ y”,“ z”)和HINT =(“ x”,“ y”,“ z”).当用户输入“提示”时,我希望程序从HINT返回相应的值.我试过了:

for h in HINT:
    if guess=="hint":
        print h

显然,这是行不通的,只是打印所有的HINT值.

如果我有:

hints=dict(zip(WORDS, HINT))
if guess=="hint":
    print "Here's a hint:", hints[correct]
while (guess !=correct) and (guess != ""):
    print "Sorry, that's not the answer."
    guess=raw_input("Your guess: ")
    guess=guess.lower()
    if guess==correct:
        print "That's it! You guessed it!\n"
print "Thanks for playing."

有什么办法让我不打印“对不起,不是吗?”? (同样,“正确”是这个词)

解决方法:

创建字典:

  hints = dict(zip(WORD, HINT))

接着:

  if guess=='hint':
    print hints[current_word]

简单还不够吗?

if guess != 'hint':
  print "Sorry, that's not the answer."
上一篇:在Python中这样的代码:a_list [i,j] = 3


下一篇:检查Java中的字典中是否存在元组键