【发布时间】:2013-01-17 02:34:58
【问题描述】:
我正在做一个问答游戏,当我被问到任何问题时,我会输入正确的答案,我在包含正确答案的变量中定义了正确答案,但如果不是第一个则表示错误该变量的单词(在本例中为 Metallica)。这是我的代码的样子。
q1answer = "Metallica" or "metallica" or "Slayer" or "slayer" or "Anthrax" or "anthrax" or "Megadeth" or "megadeth"
answerinput = str(input("name one of the 'Big Four' metal bands'"))
if answerinput == q1answer:
print ("You got the right answer!")
else:
print ("That is the wrong answer...")
现在,如果我输入“Metallica”,那将是正确的,因为它是 q1answer 变量的第一个单词。但是,如果我输入 metalica、Slayer、slayer、Anthrax、anthrax、megadeth 或 Megadeth,我会得到错误的答案文本。如果我要键入除该变量中的第一个单词以外的任何内容,是否有办法让所有这些字符串都适用于这个变量?我是python的菜鸟,所以任何帮助都会很棒。
【问题讨论】:
-
顺便说一句:
input("...")可以直接使用,str(input("..."))不需要。 -
虽然使用
raw_input("...")会更好 -
@elssar:OP 使用的是 Python 3.3。
标签: python string variables python-3.3