【发布时间】:2021-07-09 18:11:28
【问题描述】:
我正在编译一个程序,通过编写主题名称或教师姓名,打开会议的链接,但是当我编写教师姓名时,程序中插入的第一个链接总是打开而不是请求的那个。代码如下:
import webbrowser
mess = input("Enter the teacher's name or subject:")
if mess == "teacher1" or "physics":
webbrowser.open("link of teacher1")
elif mess != "teacher1" or "physics":
print("Invalid name")
input("Press ENTER to exit")
elif mess == "teacher2" or "chemistry":
webbrowser.open("link of teacher2")
elif mess != "teacher2" or "chemistry":
print("Invalid name")
input("Press ENTER to exit")
elif mess == "teacher3" or "Math":
webbrowser.open("link of teacher3")
elif mess != "tacher3" or "Math":
print("Invalid name")
input("Press ENTER to exit")
【问题讨论】:
-
"teacher1" or "physics"this 总是计算为 True 所以这个 if 语句将始终被选中 -
非常感谢,现在我试试
-
如果您想评估该值是否等于teacher1 或该值是否等于物理,请执行以下操作:
if mess == 'teacher1' or mess == 'physics':,其余的您也应该这样做
标签: python python-3.x if-statement url hyperlink