86 lines
3.4 KiB
Python
86 lines
3.4 KiB
Python
# Rock-Paper-Scissors Game
|
|
import random
|
|
|
|
options = ("rock", "paper", "scissors")
|
|
player = None
|
|
computer = None
|
|
running = True
|
|
still_playing = True
|
|
player_wins, computer_wins = 0, 0
|
|
player_losses, computer_losses = 0, 0
|
|
ties = 0
|
|
|
|
print("--------------------------------------------------")
|
|
print(" Python Rock-Paper-Scissors Game ")
|
|
print("--------------------------------------------------")
|
|
|
|
while still_playing:
|
|
while running:
|
|
player = input("Enter your choice (rock, paper, scissors) ").lower()
|
|
while player not in options:
|
|
print("INVALID entry")
|
|
player = input("Please enter your choice (rock, paper, scissors) ").lower()
|
|
continue
|
|
computer = random.choice(options)
|
|
if player == "rock" and computer == "scissors":
|
|
print(f" Player choice: {player} ")
|
|
print(f"Computer choice: {computer}")
|
|
print("You win!")
|
|
player_wins += 1
|
|
computer_losses += 1
|
|
print("--------------------------------------------------")
|
|
break
|
|
elif player == "paper" and computer == "rock":
|
|
print(f" Player choice: {player} ")
|
|
print(f"Computer choice: {computer}")
|
|
print("You win!")
|
|
player_wins += 1
|
|
computer_losses += 1
|
|
print("--------------------------------------------------")
|
|
break
|
|
elif player == "scissors" and computer == "paper":
|
|
print(f" Player choice: {player} ")
|
|
print(f"Computer choice: {computer}")
|
|
print("You win!")
|
|
player_wins += 1
|
|
computer_losses += 1
|
|
print("--------------------------------------------------")
|
|
break
|
|
elif player == computer:
|
|
print(f" Player choice: {player} ")
|
|
print(f"Computer choice: {computer}")
|
|
print("It's a tie!")
|
|
ties += 1
|
|
print("--------------------------------------------------")
|
|
break
|
|
else:
|
|
print(f" Player choice: {player} ")
|
|
print(f"Computer choice: {computer}")
|
|
print("You lose!")
|
|
player_losses += 1
|
|
computer_wins += 1
|
|
print("--------------------------------------------------")
|
|
running = False
|
|
answer = input("Play again? (y/n) ").lower()
|
|
if not answer == "y":
|
|
still_playing = False
|
|
print("--------------------------------------------------")
|
|
print(" Game Score Recap ")
|
|
print("--------------------------------------------------")
|
|
print(f"Player had {player_wins} win(s), {player_losses} loss(es) and {ties} tie(s).")
|
|
print(f"Computer had {computer_wins} win(s) and {computer_losses} loss(es).")
|
|
if (player_wins > 0 and computer_wins >= 0) or (player_wins >= 0 and computer_wins > 0):
|
|
player_percentage_wins = player_wins/(player_wins + computer_wins) * 100
|
|
print(f"Player win percentage is: {player_percentage_wins:.1f}%")
|
|
print("--------------------------------------------------")
|
|
print("Thanks for playing. Goodbye!\n")
|
|
else:
|
|
print("No one scored in this game!")
|
|
print("--------------------------------------------------")
|
|
print("Thanks for playing. Goodbye!\n")
|
|
else:
|
|
running = True
|
|
still_playing = True
|
|
|
|
|