给出“提示”的问题

3 投票
1 回答
725 浏览
提问于 2025-04-15 19:04

我有一个简单的文字混淆游戏。我已经把文字混淆做好了,但现在我想添加一个“提示”系统。我不知道怎么从元组中显示一个项目。我有两个元组,我想根据第一个元组的内容从第二个元组中提取信息。我有 WORD=("x", "y", "z")HINT=("x", "y", "z")。当用户输入 "hint" 时,我希望程序能返回对应的 HINT 值。我试过:

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

显然,这样做不行,只会打印出所有的提示值。

如果我有:

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 个回答

3

创建一个字典:

  hints = dict(zip(WORD, HINT))

然后:

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

简单的 if 不够用吗?

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

撰写回答