我有一个简单的拼字游戏。我已经搞砸了,但现在我想添加一个“提示”系统。我不知道如何显示元组中的 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."
我有什么办法让它不打印“抱歉,不是这样。”吗? (另外,这里是“正确”这个词)
最佳答案
创建字典:
hints = dict(zip(WORD, HINT))
然后:
if guess=='hint':
print hints[current_word]
简单的 if
还不够吗?
if guess != 'hint':
print "Sorry, that's not the answer."
关于python - 给出 'hints' 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2229618/