Last active
March 5, 2023 11:59
-
-
Save naazeri/52e53b12ceb8ef5d77a72b10aa960d29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
# choices in game. r=rock, p=paper, s=scissors | |
choices = ['r', 'p', 's'] | |
# get user input | |
userChoice = input('Choose your weapon [r]ock, [p]aper, or [s]cissors: ') | |
if userChoice not in choices: | |
print('Invalid input') | |
exit() | |
# get random item from array | |
aiChoice = random.choice(choices) | |
print("You chose: " + userChoice) | |
print("AI chose: " + aiChoice) | |
# check winner | |
if userChoice == aiChoice: | |
print('Equal!') | |
elif userChoice == 's' and aiChoice == 'r': | |
print('AI Win! Scissors beats rock') | |
elif userChoice == 'p' and aiChoice == 's': | |
print('AI Win! Scissors beats paper') | |
elif userChoice == 'r' and aiChoice == 'p': | |
print('AI Win! Paper beat rock') | |
else: | |
print('You WIN! :)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment