我有一个停车系统的代码。当空格的数量超过20个时,它会发送错误消息,因为20是空格的限制。我想在这之后尝试关闭程序。
我试过用Python做你能做的事情。这是:
import sys
display.scroll("Error: Limit exceeded.")
sys.exit()这给了我一个属性错误。
from microbit import *
import sys
elif spaces > 20:
display.scroll("Error: The spaces have exceeded the limit.")
sys.exit()这应该会在elif语句之后关闭程序,而不是让它工作。有更多的代码(if语句,循环,函数),但它是不相关的。
谢谢:)
发布于 2019-04-02 19:10:25
我可以想到几种方法。
通常,您可以只进入无限循环,如果无法中断循环,这将有效地停止所有操作:
while True:
microbit.sleep(1000000) # wait for 1000 seconds until the end of time在micro:bit的文档中还有microbit.panic(),引用一下,它“需要重新启动”micro:bit:
microbit.panic(0)你可以看看这对你是否有效。
由于micro:bit使用MicroPython作为其Python实现,因此您可以在MicroPython文档中查找here:
import pyb
pyb.stop() # stop CPU, waiting for external interrupt但是,如果确实发生了外部中断(可能会发生中断),程序可能会继续运行。
发布于 2019-04-05 17:42:50
您的代码片段有点误导,因为它必须在while True:循环中。就是突破了那个外环。
https://stackoverflow.com/questions/55473161
复制相似问题