Last active
August 21, 2020 12:15
-
-
Save arlyon/f49e0c006911c77132591a3aeb4ec725 to your computer and use it in GitHub Desktop.
Simple extensible rock paper scissors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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