KRITSADA icon

Once the program has run 3 times print best time with button b and average with button a

KRITSADA | PRO | 08/22/21 04:06:05 PM UTC | 0 ⭐ | 1911 👁️ | Never ⏰ | []
Python |

720 B

|

None

|

0 👍

/

0 👎

from microbit import *
import random
 
tries = 3
times = []
for i in range(tries):
  counter = 0
  sleep_time = random.randint(2000,5000) #creates a random number between 2000 and 5000
  sleep(sleep_time) # does nothing for 2-5 seconds 
  display.show(Image.SKULL) 
  while True:
    counter += 1
    sleep(10)
    if button_a.is_pressed():
      display.scroll(str(counter) + 'hundrethds',60) # prints out reaction time
      times.append(counter)
      break
    
#TASK 2: Once the program has run 3 times print best time with button b and average with button a
 
while True:
  if button_a.was_pressed():
    display.scroll(str(sum(times)/3))
  if button_b.was_pressed():
    display.scroll(str(min(times)))
    

Comments