【发布时间】:2020-07-03 02:54:55
【问题描述】:
当我运行程序时,它只会运行第一个 If 并进行那些特定的更改。当我切换它们时注意到了,只有第一个给了我想要的东西......谢谢你的帮助。
if SW1 != r['SW1']: #check the received value of SW1 & change it on the App if there is a mismatch
print("Changing SW1 status to the value in the database.")
if self.sw1.active == True:
self.sw1.active = False
else:
self.sw1.active = True
else:
return
if LED1 != r['LED1']: #check the received value of led1 & change it on the App if there is a mismatch
print("Changing LED1 status to the value in the database.")
if self.led1.active == True:
self.led1.active = False
else:
self.led1.active = True
else:
return
if LED2 != r['LED2']: #check the received value of led2 & change it on the App if there is a mismatch
print("Changing LED2 status to the value in the database.")
if self.led2.active == True:
self.led2.active = False
else:
self.led2.active = True
else:
if LED3 != r['LED3']: #check the received value of led3 & change it on the App if there is a mismatch
print("Changing LED3 status to the value in the database.")
if self.led3.active == True:
self.led3.active = False
else:
self.led3.active = True
else:
return
【问题讨论】:
-
你能分享你的代码吗?
-
@Mendelg 抱歉,不允许发布 sn-p。刚刚添加了代码。谢谢。
-
将
return放入else子句时会发生什么?您确定要在其中一个失败后使该功能短路吗? -
如果条件总是检查 TRUE 如果是,那么它不会执行 else 语句。但是,如果您想检查多个语句是否为 TRUE,请使用多个 'if'。
-
请指定您希望在哪个部分检查多个语句为真。
标签: json python-3.x if-statement