2017-05-12 2 views
0

私はどのアクセスポイントがどのスイッチに接続されているか表示されるいくつかの小さなプログラムに取り組んでいます。しかし、私がenterboxに "5"を入力するたびにmag15からの出力が得られます。問題が何であるか把握する手助けができますか? Btw私はプログラミングで吸うので、私を負担してください。事前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

ありがとうございました!あなたはその男です。 :) –