简体   繁体   English

如果数字模式为x次

[英]If number patter for x times

The situation is that I have a sensor that gives of numbers from the distance on 0cm to 700cm every 2 seconds. 情况是,我有一个传感器,每2秒给出一次从0cm到700cm距离的数字。

Is it possible to execute a code that reads the last five printed numbers and if they are all above 400cm for it to print something? 是否可以执行读取最后五个打印数字的代码,如果它们都在400厘米以上,以便打印一些内容?

def read_sensor(data={}):
    value = get_next_value()
    data["sum"] = (data.get("sum",0)+(value>400))*(value>400)
    return data["sum"]

list(iter(read_sensor,5))
print "OK I got 5 values all over 400"

is one possible way ... I guess ... your co workers might hate you ... 是一种可能的方式...我想...您的同事可能会讨厌您...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM