Skip to content

Instantly share code, notes, and snippets.

@steezeburger
Last active July 16, 2022 06:15
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 steezeburger/0c5a856b41f3af4e1dcde9912b411d7f to your computer and use it in GitHub Desktop.
Save steezeburger/0c5a856b41f3af4e1dcde9912b411d7f to your computer and use it in GitHub Desktop.
from random import randint
hands = ['rock', 'scissors', 'paper']
judgements = ['It is a draw.', 'You lost to a computer!', 'You win I guess.']
while True:
try:
user_input = input('Your weapon of choice: ')
user_choice_index = hands.index(user_input.lower())
except ValueError:
print(f'{user_input} is not an accepted weapon!')
break
npc_choice_index = randint(0, 2)
npc_choice_label = hands[npc_choice_index]
judgement = judgements[user_choice_index - npc_choice_index]
top_string = f'# The computer played {npc_choice_label}! #'
top_btm_border = '#' * len(top_string)
judgement_w_border = f'# {judgement.center(len(top_string) - 4)} #'
print(top_btm_border)
print(top_string)
print(judgement_w_border)
print(top_btm_border)
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment