SHOW:
|
|
- or go back to the newest paste.
1 | from microbit import * | |
2 | import random | |
3 | ||
4 | tries = 3 | |
5 | times = [] | |
6 | for i in range(tries): | |
7 | counter = 0 | |
8 | sleep_time = random.randint(2000,5000) #creates a random number between 2000 and 5000 | |
9 | sleep(sleep_time) # does nothing for 2-5 seconds | |
10 | display.show(Image.SKULL) | |
11 | while True: | |
12 | counter += 1 | |
13 | sleep(10) | |
14 | if button_a.is_pressed(): | |
15 | display.scroll(str(counter) + 'hundrethds',60) # prints out reaction time | |
16 | times.append(counter) | |
17 | break | |
18 | ||
19 | #TASK 2: Once the program has run 3 times print best time with button b and average with button a | |
20 | ||
21 | while True: | |
22 | if button_a.was_pressed(): | |
23 | display.scroll(str(sum(times)/3)) | |
24 | if button_b.was_pressed(): | |
25 | display.scroll(str(min(times))) | |
26 |