I have some code for a simple rev counter on the Microbit. When returning the variable rev_per_second, sometimes it is a NoneType (for reasons unknown). I try to trap this within the function, but it doesn't seem to work. Where am I going wrong please.
# 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))