-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRock_Paper_Scissors_game.py
More file actions
50 lines (44 loc) · 1.84 KB
/
Rock_Paper_Scissors_game.py
File metadata and controls
50 lines (44 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This is rock, paper, and scissors game
# The game is between player and computer
# The player will enter a choice and the computer will randomly choose a choice
# The result will be displayed on the screen
# The game will continue until the player decides to quit
# The player can quit by pressing "q" or "Q"
# The player can enter "rock", "paper", or "scissors" to play the game
# Rules: rock beats scissors, scissors beats paper, paper beats rock
# Date created: 2024-12-28
# python library
import random
# variables & functions
def get_choices():
player_choice = input("Enter a choice (rock, paper, scissors): ")
options = ["rock", "paper", "scissors"]
computer_choice = random.choice(options)
choices = {"player": player_choice, "computer": computer_choice}
return choices
def check_win(player, computer):
print(f"You chose: {player}, Computer chose: {computer}")
if player == computer:
return "It's a tie!"
elif player == "rock" and computer == "scissors":
return "You win!"
elif player == "rock" and computer == "paper":
return "Computer wins!"
elif player == "paper" and computer == "scissors":
return "Computer wins!"
elif player == "paper" and computer == "rock":
return "You win!"
elif player == "scissors" and computer == "rock":
return "Computer wins!"
elif player == "scissors" and computer == "paper":
return "You win!"
else:
return "Invalid input! You have not entered rock, paper or scissors, try again."
while True:
choices = get_choices()
result = check_win(choices["player"], choices["computer"])
print(result)
play_again = input("Do you want to play again? (yes/no): ")
if play_again.lower() != "yes":
print("Thank you for playing!")
break