我有一些用于 Microbit 上的简单转速计数器的代码。返回变量 rev_per_second 时,有时它是 NoneType(原因未知)。我试图在函数中捕获它,但它似乎不起作用。请问我哪里错了。
# part of the function revs()
if end_time < running_time():
try:
rev_per_second = rev_per_second
except TypeError:
rev_per_second = 1
return rev_per_second # make this value available to the main program
# main part of the program
while True:
rev_per_min = revs() # sometimes this is "None" Why??
display.scroll(str(rev_per_min))