Created
March 3, 2023 21:21
-
-
Save bmansk8/00fb28d5932179f116407b63006d5dc7 to your computer and use it in GitHub Desktop.
Rock Paper Scissors game
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
from random import randint | |
import re | |
def player_win_outcome(player_value,computer_value,): | |
print("you win!",player_value, "beats", computer_value, "!") | |
def player_loss_outcome(player_value,computer_value,): | |
print("you lose!",player_value, "loses to", computer_value, "!") | |
def tie(): | |
print("That's a tie!") | |
def game_loop(): | |
choices = ["Rock","Paper","Scissors"] | |
random_number = randint(0,2) | |
computer = choices[random_number] | |
player = False | |
while player == False: | |
player = input("Rock, Paper Scissors? \n") | |
if re.search( r"rock" , player, re.IGNORECASE ): | |
player = choices[0] | |
elif re.search( r'paper' , player,re.IGNORECASE ): | |
player = choices[1] | |
elif re.search( r'scissors' , player, re.IGNORECASE ): | |
player = choices[2] | |
else: | |
print("That's not a valid play. Check your spelling!") | |
return | |
if player == computer: | |
tie() | |
elif player == "Rock": | |
if computer == "Paper": | |
player_loss_outcome(player, computer) | |
else: | |
player_win_outcome(player, computer) | |
elif player == "Paper": | |
if computer == "Scissors": | |
player_loss_outcome(player, computer) | |
else: | |
player_win_outcome(player, computer) | |
elif player == "Scissors": | |
if computer == "Rock": | |
player_loss_outcome(player, computer) | |
else: | |
player_win_outcome(player, computer) | |
response = input("want to play again? [Y/N] \n") | |
if(response == "Y"): | |
player = False | |
computer = choices[randint(0,2)] | |
game_loop() | |
game_loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment