-
Notifications
You must be signed in to change notification settings - Fork 3k
/
mouredev.py
48 lines (33 loc) · 1.34 KB
/
mouredev.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
from enum import Enum
class Player(Enum):
P1 = 1
P2 = 2
def tenis_game(points: list):
game = ["Love", "15", "30", "40"]
p1_points = 0
p2_points = 0
finished = False
error = False
for player in points:
error = finished
p1_points += 1 if player == Player.P1 else 0
p2_points += 1 if player == Player.P2 else 0
if p1_points >= 3 and p2_points >= 3:
if not finished and abs(p1_points - p2_points) <= 1:
print("Deuce" if p1_points == p2_points else
"Ventaja P1" if p1_points > p2_points else "Ventaja P2")
else:
finished = True
else:
if p1_points < 4 and p2_points < 4:
print(f"{game[p1_points]} - {game[p2_points]}")
else:
finished = True
print("Los puntos jugados no son correctos" if error or not finished else
"Ha ganado el P1" if p1_points > p2_points else "Ha ganado el P2")
tenis_game([Player.P1, Player.P1, Player.P2, Player.P2,
Player.P1, Player.P2, Player.P1, Player.P1])
tenis_game([Player.P1, Player.P1, Player.P2, Player.P2,
Player.P1, Player.P2, Player.P1, Player.P1, Player.P2, Player.P1])
tenis_game([Player.P1, Player.P1, Player.P1, Player.P1, Player.P1, Player.P1])
tenis_game([Player.P1, Player.P1])