Skip to content

Instantly share code, notes, and snippets.

@arlyon
Last active August 21, 2020 12:15
Show Gist options
  • Save arlyon/f49e0c006911c77132591a3aeb4ec725 to your computer and use it in GitHub Desktop.
Save arlyon/f49e0c006911c77132591a3aeb4ec725 to your computer and use it in GitHub Desktop.
Simple extensible rock paper scissors.
from random import choice
logic = {
"rock": ["scissors"],
"paper": ["rock"],
"scissors": ["paper"]
}
choices = list(logic.keys())
def round(human, computer):
try:
if computer in logic[human]:
print(f"you win! {human} beats {computer}.")
elif human in logic[computer]:
print(f"computer wins: {computer} beats {human}.")
else:
print("tie")
except KeyError:
print("invalid choice")
if __name__ == '__main__':
while True:
human = input(f"{' '.join(choices)}? > ").lower()
computer = choice(choices)
round(human, computer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment