Python3.6中的input()错误

时间:2018-06-26 00:46:56

标签: user-input python-3.6

嘿,我是python的新手,我只是想制作一个要求您输入名称的程序,如果您输入名称“ Joe”,它会显示“ Hi Joe”,如果您输入其他名称,说“我不认识你。问题是我可以输入任何名称,但仍然说“嗨乔!”。我做错了什么?

print("what is your name?")
name = input()

if name == "joe" or "Joe":
    print("Hi Joe!")
else:
    print("I don't know you.")

input("press enter to exit")

1 个答案:

答案 0 :(得分:0)

print("what is your name?")
name = input()

if name.lower() == "joe": #will put everything lower case, also allows jOe 
    print("Hi Joe!")
else:
    print("I don't know you.")

input("press enter to exit")

或者使用if name == "joe" or name == "Joe: