-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissors.py
66 lines (50 loc) · 1.68 KB
/
rock_paper_scissors.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
from secrets import choice
from typing import List, Tuple
def play() -> List[Tuple[str, int]]:
highscore_lst: List[Tuple[str, int]] = []
name: str = input("What's your name? ")
player_choice: str = input("Rock, paper or scissors? ").lower()
choices: Tuple[str, str, str] = ("rock", "paper", "scissors")
if player_choice in choices:
computer_choice = choice(choices)
win_conditions = {
"rock": "scissors",
"scissors": "paper",
"paper": "rock",
}
if player_choice == computer_choice:
print("\nDraw, try again")
score = 0
elif win_conditions[player_choice] == computer_choice:
print("\nYou won")
score = 1
else:
print("\nYou lost, try again")
score = 0
highscore_lst.append((name, score))
else:
print("\nInvalid choice. Please try again")
return highscore_lst
def view_users() -> None:
highscore_lst: List[Tuple[str, int]] = play()
print("\nHighscore list\n")
for name, score in highscore_lst:
print(f"{name}: {score}")
def main() -> None:
while True:
print("\nMenu:")
print("1. Do you want to play?")
print("2. Highscore")
print("3. Exit")
player_choice: str = input("Enter your choice: ")
choices: Tuple[str, str, str] = ("1", "2", "3")
if player_choice == choices[0]:
play()
elif player_choice == choices[1]:
view_users()
elif player_choice == choices[2]:
break
else:
print("\nInvalid choice. Please try again.")
if __name__ == "__main__":
main()