-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrps_game.py
52 lines (40 loc) · 1.71 KB
/
rps_game.py
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
51
52
'''
https://github.com/lijnati/Python-Projects
To play the game, you can simply run the Python script. The program will display the options and ask you to enter your choice. The program will then determine the winner.
Note: You can play the game by using either the full name of the option (rock, paper, scissors) or the short name (r, p, s).
'''
import random
def game_choice(user_choice):
if user_choice == "r":
user_choice = "rock"
elif user_choice == "p":
user_choice = "paper"
elif user_choice == "s":
user_choice = "scissors"
return user_choice
def game_play():
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
print("\nWelcome to the Rock Paper Scissors Game!")
print("\nPlease choose between the following options:")
print("\n1. Rock - Enter 'r'")
print("\n2. Paper - Enter 'p'")
print("\n3. Scissors - Enter 's'")
print("\n")
user_choice = input("Enter your choice: ").lower()
if user_choice not in ['r', 'p', 's']:
print("\nInvalid choice! Please enter either 'r', 'p', or 's'.")
else:
user_choice = game_choice(user_choice)
print("\nYou chose " + user_choice)
print("\nThe computer chose " + computer_choice)
if user_choice == computer_choice:
print("\nIt's a tie!")
elif (user_choice == 'rock' and computer_choice == 'scissors') or \
(user_choice == 'scissors' and computer_choice == 'paper') or \
(user_choice == 'paper' and computer_choice == 'rock'):
print("\nYou win!")
else:
print("\nYou lose!")
if __name__ == "__main__":
game_play()