Skip to content

Instantly share code, notes, and snippets.

@naazeri
Last active March 5, 2023 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naazeri/52e53b12ceb8ef5d77a72b10aa960d29 to your computer and use it in GitHub Desktop.
Save naazeri/52e53b12ceb8ef5d77a72b10aa960d29 to your computer and use it in GitHub Desktop.
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