2017-05-12 110 views
0

我正在研究一些小程序,它會告訴我哪個接入點連接到什麼開關。但是當我在輸入框中輸入「5」時,我會從mag15中獲得輸出。你們能幫我弄清楚問題是什麼嗎?順便說一句,我喜歡編程,所以忍受着我。在此先感謝Python錯誤的輸出輸入框

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") 

回答

0

mag01 = "mag01" or "MAG01" or "1" or "01"是完全等同於mag01 = "mag01" - 在or運營商採取的第一個「truthy」值,和所有非空字符串truthy。

由於最終目標是一個in檢查多個值,你想要的是mag01 = ("mag01", "MAG01", "1", "01")作出一個元組(一個列表也將工作)。跳過mag01 = str(mag01),完成任何事情。

+0

謝謝你!你是那個人。 :) –