Created
February 22, 2023 07:54
-
-
Save barseghyanartur/5d7009b738ae275c8fdecdd8f4bfb316 to your computer and use it in GitHub Desktop.
Rock, paper, scissors game in Python
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
""" | |
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