Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created August 9, 2017 07:20
Show Gist options
  • Save uktechreviews/c676d2df6dbc1dc53df782ff9d5aee99 to your computer and use it in GitHub Desktop.
Save uktechreviews/c676d2df6dbc1dc53df782ff9d5aee99 to your computer and use it in GitHub Desktop.
from gpiozero import Button
from gpiozero import LED
import time
import random
button1 = Button(2)
button2 = Button(3)
led1 = LED(20)
led2 = LED(21)
fail = False
score = 0
led1.off()
led2.off()
def check_button():
button_press = False
while button_press == False:
b1 = button1.value
b2 = button2.value
if b1 == True:
button_press = True
if b2 == True:
button_press = True
return b1,b2
while fail == False:
list = (1,2)
choice = random.choice(list)
if choice == 1:
led1.on()
led2.off()
if choice == 2:
led1.off()
led2.on()
time.sleep(0.5)
led1.off()
led2.off()
b1,b2 = check_button()
if choice == 1 and b1 == True:
print ("Correct")
score +=1
fail = False
elif choice == 2 and b2 == True:
print ("Correct")
score +=1
fail = False
else:
print ("wrong")
fail = True
print ("Your score " + str(score))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment