Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Created February 22, 2023 07:54
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 barseghyanartur/5d7009b738ae275c8fdecdd8f4bfb316 to your computer and use it in GitHub Desktop.
Save barseghyanartur/5d7009b738ae275c8fdecdd8f4bfb316 to your computer and use it in GitHub Desktop.
Rock, paper, scissors game in Python
"""
Usage:
python rock_paper_scissors.py
"""
import random
__title__ = "rock_paper_scissors"
__version__ = "0.1"
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
__copyright__ = "2023 Artur Barseghyan"
__license__ = "MIT"
while True:
print("Enter your choice (1: Rock, 2: Paper, 3: Scissors):")
user_choice = int(input())
while user_choice not in [1, 2, 3]:
print(
"Invalid choice. Please enter a valid "
"choice (1: Rock, 2: Paper, 3: Scissors):"
)
user_choice = int(input())
choices = {1: "rock", 2: "paper", 3: "scissors"}
computer_choice = random.randint(1, 3)
if user_choice == computer_choice:
print(
f"{choices[user_choice]} vs {choices[computer_choice]}. It's a tie!"
)
elif (
(user_choice == 1 and computer_choice == 3)
or (user_choice == 2 and computer_choice == 1)
or (user_choice == 3 and computer_choice == 2)
):
print(
f"{choices[user_choice]} beats {choices[computer_choice]}. You win!"
)
else:
print(
f"{choices[computer_choice]} beats {choices[user_choice]}. I win!"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment