from machine import Pin
from time import sleep, ticks_us
import random
A = Pin(1, Pin.OUT)
B = Pin(2, Pin.OUT)
C = Pin(3, Pin.OUT)
D = Pin(4, Pin.OUT)
E = Pin(5, Pin.OUT)
F = Pin(6, Pin.OUT)
G = Pin(7, Pin.OUT)
button = Pin(17, Pin.IN)
print("Press the button to show a random number!")
while True:
while button.value() == 0:
sleep(0.1)
random.seed(ticks_us())
chances = 3
total = 0
print("Game Started! You have 3 chances.")
while chances > 0:
while button.value() == 0:
sleep(0.1)
num = random.randint(0, 9)
A.value(0)
B.value(0)
C.value(0)
D.value(0)
E.value(0)
F.value(0)
G.value(0)
if num in (0, 2, 3, 5, 6, 7, 8, 9):
A.value(1)
if num in (0, 1, 2, 3, 4, 7, 8, 9):
B.value(1)
if num in (0, 1, 3, 4, 5, 6, 7, 8, 9):
C.value(1)
if num in (0, 2, 3, 5, 6, 8, 9):
D.value(1)
if num in (0, 2, 6, 8):
E.value(1)
if num in (0, 4, 5, 6, 8, 9):
F.value(1)
if num in (2, 3, 4, 5, 6, 8, 9):
G.value(1)
print("You got:", num)
total = total + num
chances = chances - 1
print("Chances ledt", chances)
sleep(1)
while button.value() == 1:
sleep(0.1)
print("Game Over! Total Score", total)
print("Press the button to start game again.\n")
while button.value() == 0:
sleep(0.1)