嘿,我是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")
答案 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: