3 ms·
def learn(thing, max_time=0, max_attempts=1): while run_time < max_time: while attempts < max_attempts: attempts =+ 1 if do(thing)
by killjoywashere 9y ago
def learn(thing, max_time=0, max_attempts=1):
while run_time < max_time:
while attempts < max_attempts:
attempts =+ 1
if do(thing) = 0
break
else
learn(thing)
Always set a time limit or a maximum number of attempts. Default to at least try (you may already know it).
Edit: I don't write code very much, and certainly don't claim to earn my living on it.
- dragonwriter 9y agoPedantically, aside from the values that are tested without being initialized, with the default values, this always fails at the first test of the outer loop, without making any attempts.
- killjoywashere 9y agoGood thing I don't write code for a living.