Last active
January 15, 2023 07:08
-
-
Save Brandon-Gui123/f38cd5863acff02eec3cccbf1464f1d4 to your computer and use it in GitHub Desktop.
Rock Paper Scissors, written in Python
This file contains hidden or 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
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