from machine import Pin, PWM
import random, sys
rock = Pin(16, Pin.IN, Pin.PULL_UP)
paper = Pin(17, Pin.IN, Pin.PULL_UP)
scissors = Pin(18, Pin.IN, Pin.PULL_UP)
lose_led = Pin(0, Pin.OUT)
win_led = Pin(1, Pin.OUT)
print("Please press a button to indicate your choice")
print("Red is rock, yellow is paper, blue is scissors")
replay = True
while replay:
possible_actions = [rock, paper, scissors]
computer_action = random.choice(possible_actions)
rock_state = rock.value()
paper_state = paper.value()
scissors_state = scissors.value()
if rock_state == 0 or paper_state == 0 or scissors_state == 0:
if rock_state == 0:
user_action = rock
if user_action == computer_action:
print("It's a tie!")
elif computer_action == scissors:
win_led.on()
print("Rock beats scissors! You win!")
else:
lose_led.on()
print("Paper beats rock... Better luck next time!")
#break
elif paper_state == 0:
user_action = paper
if user_action == computer_action:
print("It's a tie!")
elif computer_action == scissors:
lose_led.on()
print("Scissors beats paper... Better luck next time!")
else:
win_led.on()
print("Paper beats rock! You win!")
#break
elif scissors_state == 0:
user_action = scissors
if user_action == computer_action:
print("It's a tie!")
elif computer_action == rock:
lose_led.on()
print("Rock beats scissors... Better luck next time!")
else:
win_led.on()
print('Scissors beats paper! You win!')
#break
Play_again = input("Play again? (y/n)")
if Play_again.lower() == "n":
replay = False
else:
replay = True