-
Notifications
You must be signed in to change notification settings - Fork 0
/
02b.py
42 lines (35 loc) · 900 Bytes
/
02b.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
iwin = {
'A': 'Y',
'B': 'Z',
'C': 'X',
}
ilose = {
'A': 'Z',
'B': 'X',
'C': 'Y',
}
equiv = {
'A': 'X',
'B': 'Y',
'C': 'Z',
}
value = {
'X': 1,
'Y': 2,
'Z': 3,
}
with open("02-i.txt", "r") as fh:
totalscore = 0
for line in fh:
score = 0
opponent, strategy = line.strip().split(" ")
if strategy == "X": # I must lose -> 0 + value of losing letter
score += 0 + value[ilose[opponent]]
elif strategy == "Y": # I must draw -> 3 + value of opponent's letter
score += 3 + value[equiv[opponent]]
elif strategy == "Z": # I must win -> 6 + value of winning letter
score += 6 + value[iwin[opponent]]
print(opponent, strategy, score)
totalscore += score
print("------------")
print("TOTAL SCORE:", totalscore)