-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual_rps.py
82 lines (53 loc) · 2.25 KB
/
manual_rps.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import random
def get_computer_choice():
'''The function "get_computer_choice" returns a randomly chosen move from a list of "Rock",
"Paper", and "Scissors".
Returns
-------
a randomly chosen move from the list of "Rock", "Paper", and "Scissors".
'''
moves = ["Rock", "Paper", "Scissors"]
computer_choice = random.choice(moves)
return computer_choice
def get_user_choice():
'''This function prompts the user to choose between Rock, Paper, or Scissors and returns their
choice.
Returns
-------
the user's choice of either "Rock", "Paper", or "Scissors".
'''
while True:
user_choice = input("Please choose Rock, Paper or Scissors: ").capitalize()
if user_choice in ["Rock", "Paper", "Scissors"]:
return user_choice
else:
print("Please choose either Rock, Paper, or Scissors")
def get_winner(computer_choice, user_choice):
'''The function takes in two choices (computer and user) and determines the winner based on the
rules of rock-paper-scissors.
Parameters
----------
computer_choice
The choice made by the computer in a game of rock-paper-scissors.
user_choice
The choice made by the user, which can be "Rock", "Paper", or "Scissors".
'''
if computer_choice == "Rock" and user_choice == "Paper":
print("You won!")
elif computer_choice == "Rock" and user_choice == "Scissors":
print("You lost!")
elif computer_choice == "Paper" and user_choice == "Rock":
print("You lost!")
elif computer_choice == "Paper" and user_choice == "Scissors":
print("You won!")
elif computer_choice == "Scissors" and user_choice == "Rock":
print("You won!")
elif computer_choice == "Scissors" and user_choice == "Paper":
print("You lost!")
elif computer_choice == user_choice:
print("It's a tie!")
def play():
'''Plays the game by running the above functions.'''
get_winner(get_computer_choice(), get_user_choice())
if __name__ == "__main__":
play()