PY
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
from types import MappingProxyType
class Score:
show = True #for auto display
def __init__(self):
self._subjects = MappingProxyType({
'English':[0],
'Math':[0],
'Science':[0],
})
#tuple as key 😅. obviously,there must be no duplication on the abbreviations.
self._alias = {
('English','english','En',
'en','E','e'):'English',
('Math','math','Ma','ma','M','m'):
'Math',
('Science','science','Sc',
'sc','S','s'):'Science'
}
def set(self, sub, scr):
for s in self._alias:
if sub in s:
sub = self._alias[s]
try:
# keep score between 0 and 100
if scr>=0 and scr<=100:
self._subjects[sub][0] = scr
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run