给出“提示”问题

时间:2010-02-09 14:10:12

标签: python tuples

我有一个简单的单词jumble游戏。我已经犯了混乱,但现在我想添加一个'提示'系统。我不知道如何从元组中显示1个项目。我有2个元组,我想根据第一个元组的内容从第二个元组中拉出来。我有WORD=("x", "y", "z")HINT=("x", "y", "z")。当用户输入"hint"时,我希望程序从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."

我有什么方法可以让它不打印“对不起,那不是它。”? (另外,'正确'在这里是这个词)

1 个答案:

答案 0 :(得分:3)

创建字典:

  hints = dict(zip(WORD, HINT))

然后:

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

简单if是不够的?

if guess != 'hint':
  print "Sorry, that's not the answer."