我还没有找到满足我的需求的答案,或者足够简单,因此我实际上可以理解,因为我是相对较新的python!试图将使用中的变量更改为用户输入的内容
我有一个变量标记为难度,要求用户输入一个字符串来表明他们是否想要简单的中等或硬模式。不幸的是,我无法成功地让python检查所用单词的输入,并给他们我想要的东西,最后我以“易于未定义”或“中等未定义”或“难以定义”结束。有没有办法让我解决这个问题?这里是一个问题被封闭,以我的一小段代码:
difficulty=input("What difficulty do you wish to choose, easy,medium or hard?")
if difficulty==easy:
print("You have chosen the easy mode, your test will now begin")
print("")
elif difficulty==medium:
print("You have chosen the medium mode, your test will now begin")
else:
print("You have chosen the hard mode or tried to be funny, your test
will now begin")
您必须将输入与一个字符串进行比较:'if difficult ==“easy”:' – Prune
'难度==“简单”'。这里需要字符串文字。 –
@Jan'raw_input'已从版本3的python中删除。 –