Skip to content

Instantly share code, notes, and snippets.

@Brandon-Gui123
Last active January 15, 2023 07:08
Show Gist options
  • Save Brandon-Gui123/f38cd5863acff02eec3cccbf1464f1d4 to your computer and use it in GitHub Desktop.
Save Brandon-Gui123/f38cd5863acff02eec3cccbf1464f1d4 to your computer and use it in GitHub Desktop.
Rock Paper Scissors, written in Python
import random
print("Welcome to a game of Rock Paper Scissors!")
while True:
# ask whether to play rock, paper or scissors
user_choice = input("Choose one (rock, paper, scissors): ").strip().lower()
# validate input
if user_choice == "":
print("You need to choose one!")
elif user_choice not in ("rock", "paper", "scissors"):
print("That's not a valid option!")
else:
break
# let the computer decide
computer_choice = random.choice(("rock", "paper", "scissors"))
# compare with what the computer chooses
if user_choice == computer_choice:
print("It's a draw!")
else:
player_win_combinations = (("rock", "scissors"), ("paper", "rock"), ("scissors", "paper"))
if (user_choice, computer_choice) in player_win_combinations:
print(f"You won against computer's {computer_choice}!")
else:
print(f"You lost against computer's {computer_choice}!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment