Python 错误的输出输入框

Python Wrong output enterbox

我正在开发一些小程序,它会告诉我哪个接入点连接到哪个交换机。但是每当我在输入框中输入“5”时,我都会从 mag15 获得输出。你们能帮我弄清楚问题是什么吗?顺便说一句,我很不擅长编程,所以请多多包涵。提前致谢

import easygui


mag01 = "mag01" or "MAG01" or "1" or "01"
mag02 = "mag02" or "MAG02" or "2" or "02"
mag03 = "mag03" or "MAG03" or "3" or "03"
mag04 = "mag04" or "MAG04" or "4" or "04"
mag05 = "mag05" or "MAG05" or "5" or "05"
mag06 = "mag06" or "MAG06" or "6" or "06"
mag07 = "mag07" or "MAG07" or "7" or "07"
mag08 = "mag08" or "MAG08" or "8" or "08"
mag09 = "mag09" or "MAG09" or "9" or "09"
mag10 = "mag10" or "MAG10" or "10"
mag11 = "mag11" or "MAG11" or "11"
mag12 = "mag12" or "MAG12" or "12"
mag13 = "mag13" or "MAG13" or "13"
mag14 = "mag14" or "MAG14" or "14"
mag15 = "mag15" or "MAG15" or "15"
mag16 = "mag16" or "MAG16" or "16"
mag17 = "mag17" or "MAG17" or "17"
mag18 = "mag18" or "MAG18" or "18"
mag19 = "mag19" or "MAG19" or "19"
mag20 = "mag20" or "MAG20" or "20"
mag21 = "mag21" or "MAG21" or "21"
mag22 = "mag22" or "MAG22" or "22"

mag01 = str(mag01)
mag02 = str(mag02)
mag03 = str(mag03)
mag04 = str(mag04)
mag05 = str(mag05)
mag06 = str(mag06)
mag07 = str(mag07)
mag08 = str(mag08)
mag09 = str(mag09)
mag10 = str(mag10)
mag11 = str(mag11)
mag12 = str(mag12)
mag13 = str(mag13)
mag14 = str(mag14)
mag15 = str(mag15)
mag16 = str(mag16)
mag17 = str(mag17)
mag18 = str(mag18)
mag19 = str(mag19)
mag20 = str(mag20)
mag21 = str(mag21)
mag22 = str(mag22)

switch1 = "C:\Users\user\Desktop\MAGAP\Switch1.jpg"
switch2 = "C:\Users\user\Desktop\MAGAP\Switch2.jpg"
switch3 = "C:\Users\user\Desktop\MAGAP\Switch3.jpg"
switch4 = "C:\Users\user\Desktop\MAGAP\Switch4.jpg"


invoer = easygui.enterbox(msg="Voer de AP in:")
invoer = str(invoer)



if invoer in mag01 or invoer in mag02 or invoer in mag03 or invoer in mag11 or invoer in mag21 or invoer in mag15:
    easygui.msgbox(msg="Switch 01; Hal 7", image = switch1)
elif invoer in mag04 or invoer in mag06 or invoer in mag07 or invoer in mag09 or invoer in mag05:
     easygui.msgbox(msg="Switch 02; Hal 3", image = switch2)
elif invoer in mag16 or invoer in mag17 or invoer in mag18 or invoer in mag08 or invoer in mag10 or invoer in mag22:
    easygui.msgbox(msg="Switch 03; Hal 9", image = switch3)
elif invoer in mag12 or invoer in mag13 or invoer in mag14 or invoer in mag19 or invoer in mag20:
    easygui.msgbox(msg="Switch 04; Hal 9", image = switch4)
elif invoer is None:
    easygui.msgbox(msg="Onjuist of geen invoer")

mag01 = "mag01" or "MAG01" or "1" or "01" 完全等同于 mag01 = "mag01" - or 运算符采用第一个 "truthy" 值,并且所有非空字符串都是真实的。

由于最终目标是 in 检查多个值,您想要的是 mag01 = ("mag01", "MAG01", "1", "01") 创建一个元组(列表也可以)。跳过 mag01 = str(mag01),那将一事无成。