This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-general-week-05-07-answer.py
More file actions
68 lines (54 loc) · 1.67 KB
/
exercise-general-week-05-07-answer.py
File metadata and controls
68 lines (54 loc) · 1.67 KB
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
from enum import Enum
import random
class Result(Enum):
ROCK = 0
PAPER = 2
SCISSORS = 3
NOT_DEFINED = 4
class Player:
outcome = Result.NOT_DEFINED
name = None
def __init__(self, player_name) -> None:
self.name = player_name
def __str__(self) -> str:
return self.name + " - " + self.outcome.name
def play(self):
self.outcome = random.choice([Result.ROCK, Result.PAPER, Result.SCISSORS])
def winner(p1: Player, p2: Player):
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 1,2 <-----
if p1.outcome == p2.outcome:
print(f"({p1},\t{p2})\t=> Draw between ({p1.name}, {p2.name})")
return p1
elif (
(p1.outcome is Result.ROCK and p2.outcome is Result.SCISSORS)
or (p1.outcome is Result.SCISSORS and p2.outcome is Result.PAPER)
or (p1.outcome is Result.PAPER and p2.outcome is Result.ROCK)
):
print(f"({p1},\t{p2})\t=> {p1.name} is stronger")
return p1
else:
print(f"({p1},\t{p2})\t=> {p2.name} is stronger")
return p2
player1 = Player("PLAYER 1")
player2 = Player("PLAYER 2")
player3 = Player("PLAYER 3")
player1.play()
player2.play()
player3.play()
print(player1)
print(player2)
print(player3)
print("------------")
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 2 <-----
if player1.outcome == player2.outcome == player3.outcome:
print("Draw between 3 players")
elif (
player1.outcome != player2.outcome
and player2.outcome != player3.outcome
and player1.outcome != player3.outcome
):
print("Everyone can attack the other one!")
else:
winner(winner(player1, player2), player3)