from random import choice
player_victory_ascii = r"""
.oo.
oGGGGGGo
GGGGGGGGGG
.mMMMMMMGGGGGGEEEE=
MMMMMMMMMMMGGEEEEEEEE
MMMMMMMMMMMNICKEEEEEEEE
MMMMMMMMMMMMMEEEEEEEEEE
!MMMMMMMMMMMOOEEEEEEEE
MMM!MMMMMMOOOOOOE!=
MM!!!!!!!!!!!!!!!
MM!!!!!!!!!!!!!'
!M!!!!!!!!!!!!!
MM!!!!!!!!!!!'
MM!!!!!!!!!!!
! `!!!!!!!!!'
. !!!!!!!!!
`!!!!!!!'
!!!!!!!
`!!!!!'
!!!!!
`!!!'
!!!
`!'
!
"""
computer_victory_ascii = r"""
_______________ |*\_/*|________
| ___________ | .-. .-. ||_/-\_|______ |
| | | | .****. .****. | | | |
| | 0 0 | | .*****.*****. | | 0 0 | |
| | - | | .*********. | | - | |
| | \___/ | | .*******. | | \___/ | |
| |___ ___| | .*****. | |___________| |
|_____|\_/|_____| .***. |_______________|
_|__|/ \|_|_.............*.............._|________|_
/ ********** \ / ********** \
/ ************ \ / ************ \
-------------------- --------------------
"""
def display_choices(player_choice, computer_choice):
print(f"Player chooses: {valid_choices[player_choice]}")
print(f"Computer chooses: {valid_choices[computer_choice]}")
def display_game_winner(player_wins, computer_wins):
if player_wins > computer_wins:
print(f"{player_name} wins the series!")
print(player_victory_ascii)
elif computer_wins > player_wins:
print("Computer wins the series!")
print(computer_victory_ascii)
else:
print("The series tied!")
def find_round_winner(player_choice, computer_choice):
if player_choice not in valid_choices:
return "Try again"
elif (
player_choice == "rock"
and computer_choice == "scissors"
or player_choice == "paper"
and computer_choice == "rock"
or player_choice == "scissors"
and computer_choice == "paper"
):
return "Player"
elif player_choice == computer_choice:
return "Tie"
else:
return "Computer"
def display_scoreboard(player_wins, computer_wins, num_games_played):
num_tie = num_games_played - (player_wins + computer_wins)
scoreboard = f"""
PLAYER_WINS: {player_wins}
COMPUTER_WINS: {computer_wins}
NUM_TIE: {num_tie}
NUM_GAME_PLAYED: {num_games_played}
"""
print(scoreboard)
num_games_played = 0
player_wins = 0
computer_wins = 0
valid_choices = {"rock": "✊",
"paper": "📜",
"scissors": "✂"
}
print("Welcome to Rock, Paper, Scissors!")
player_name = input("What is your name? ")
print("Your valid choices are:")
for valid_choice, emoji in valid_choices.items():
print(f"{valid_choice}: {emoji}")
while True:
player_choice = input(f"Choose rock, paper, or scissors {player_name}: ")
computer_choice = choice(list(valid_choices))
display_choices(player_choice, computer_choice)
round_winner = find_round_winner(player_choice, computer_choice)
if round_winner == "Player":
print("Player wins this round!")
player_wins += 1
elif round_winner == "Computer":
print("Computer wins this round!")
computer_wins += 1
elif round_winner == "Try again":
print("That was an invalid choice! Try again!")
continue
else:
print("This round is a tie!")
num_games_played += 1
display_scoreboard(player_wins, computer_wins, num_games_played)
keep_playing = input("Keep playing (y/n)? ")
if keep_playing != "y":
break
display_game_winner(player_wins, computer_wins)
Welcome to Rock, Paper, Scissors!
Your valid choices are:
rock: ✊
paper: 📜
scissors: ✂
Player chooses: ✊
Computer chooses: ✂
Player wins this round!
PLAYER_WINS: 1
COMPUTER_WINS: 0
NUM_TIE: 0
NUM_GAME_PLAYED: 1
Player chooses: 📜
Computer chooses: ✂
Computer wins this round!
PLAYER_WINS: 1
COMPUTER_WINS: 1
NUM_TIE: 0
NUM_GAME_PLAYED: 2
Player chooses: ✊
Computer chooses: ✊
This round is a tie!
PLAYER_WINS: 1
COMPUTER_WINS: 1
NUM_TIE: 1
NUM_GAME_PLAYED: 3
Player chooses: ✊
Computer chooses: 📜
Computer wins this round!
PLAYER_WINS: 1
COMPUTER_WINS: 2
NUM_TIE: 1
NUM_GAME_PLAYED: 4
Computer wins the series!
_______________ |*\_/*|________
| ___________ | .-. .-. ||_/-\_|______ |
| | | | .****. .****. | | | |
| | 0 0 | | .*****.*****. | | 0 0 | |
| | - | | .*********. | | - | |
| | \___/ | | .*******. | | \___/ | |
| |___ ___| | .*****. | |___________| |
|_____|\_/|_____| .***. |_______________|
_|__|/ \|_|_.............*.............._|________|_
/ ********** \ / ********** \
/ ************ \ / ************ \
-------------------- --------------------