-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.py
86 lines (72 loc) · 2.4 KB
/
program.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import hashlib
import sys
def autentifikuj():
"""vyziada a overi heslo"""
hash_hesla = open("heslo.txt").read().strip()
heslo = input("Zadaj heslo!\n")
# neda sa jednoducho testovat
# heslo = getpass.getpass(prompt='Heslo: ', stream=None)
if hashlib.sha224(heslo.encode()).hexdigest() == hash_hesla:
return True
else:
print("Nesprávne heslo")
return False
def points(hraci, hrac, body):
"""prida hracovi body"""
if autentifikuj():
if hrac in hraci:
hraci[hrac]["body"] += body
else:
hraci[hrac] = {}
hraci[hrac]["junior"] = False
hraci[hrac]["body"] = body
def reduction(hraci, percenta):
"""každému zníži počet bodov o percentá"""
if autentifikuj():
for hrac in hraci:
percent = 1 - percenta / 100
hraci[hrac]["body"] = int(hraci[hrac]["body"] * percent)
def junior(hraci, hrac):
"""označí hráča za juniora"""
if autentifikuj():
if hrac in hraci:
hraci[hrac]["junior"] = True
else:
hraci[hrac] = {}
hraci[hrac]["body"] = 0
hraci[hrac]["junior"] = True
def ranking(hraci, vsetci):
"""vypíše poradie hráčov"""
if vsetci:
for hrac in sorted(hraci.items(), key=lambda x: x[1]["body"], reverse=True):
print(hrac[0], hrac[1]["body"])
else:
for hrac in sorted(hraci.items(), key=lambda x: x[1]["body"], reverse=True):
if hrac[1]["junior"]:
print(hrac[0], hrac[1]["body"])
def myquit():
"""ukončí program"""
if autentifikuj():
sys.exit()
if __name__ == "__main__":
hraci = {}
if autentifikuj():
while True:
prikaz = input().split()
# prazdny riadok
if len(prikaz) == 0:
continue
elif prikaz[0] == "points":
points(hraci, prikaz[1], int(prikaz[2]))
elif prikaz[0] == "reduce":
reduction(hraci, int(prikaz[1]))
elif prikaz[0] == "junior":
junior(hraci, prikaz[1])
elif prikaz[0] == "ranking":
if len(prikaz) > 1 and prikaz[1] == "junior":
vsetci = False
else:
vsetci = True
ranking(hraci, vsetci)
elif prikaz[0] == "quit":
myquit()