-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperSciccors.py
More file actions
39 lines (30 loc) · 1011 Bytes
/
RockPaperSciccors.py
File metadata and controls
39 lines (30 loc) · 1011 Bytes
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
# RockPaperSciccors game
# created on July 25
import random
def iswin(computer, human):
if computer == human:
return 0 # draw game
elif (computer - human) in [-1, 2]:
return -1 # computer wins
else:
return 1 # human wins
def game():
values = ["p", "r", "s"]
Values = ["paper", "rock", "sciccors"]
computer = values.index(random.choice(values)) # gathering indices of the list
human = values.index(
input("Enter your choice as 'r' for rock, 'p' for paper and 's' for sciccors\n")
)
# gathering indices of the list
# rock > sciccors, sciccors > paper, paper > rock
win_bool = iswin(computer, human)
match (win_bool):
case 0:
print("The game ended as as draw")
case 1:
print("You won!!", Values[human], " beats ", Values[computer])
case -1:
print("You lost!!", Values[computer], "beats", Values[human])
if __name__ == "__main__":
while True:
game()