-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_24_22.py
More file actions
54 lines (43 loc) · 1.47 KB
/
task_24_22.py
File metadata and controls
54 lines (43 loc) · 1.47 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
import json
class Person:
def __init__(self):
self.surname = None
self.byear = None
def input(self):
self.surname = input('Прізвище: ')
self.byear = input('Рік народження: ')
def print(self):
print(f'Прізвище: {self.surname}')
print(f'Рік народження: {self.byear}')
class Student(Person):
def __init__(self, filename):
Person().__init__()
self.name = None
self.course = None
self.marks = {}
self.file = filename
def input(self):
Person.input(self)
self.name = input("Ім'я: ")
self.course = input('Курс: ')
n = int(input('Кількість предметів: '))
for _ in range(n):
subject = input('Предмет: ')
mark = input('Оцінка з предмета за сесію: ')
self.marks[subject] = mark
def print(self):
Person.print(self)
print(f"Ім'я: {self.name}")
print(f'Курс: {self.course}')
for k, v in self.marks.items():
print(f'{k}: {v}')
def save(self, data):
with open(self.file, 'r+') as f:
data_json = json.load(f)
data_json.append(data)
f.seek(0)
json.dump(data_json, f, indent=4)
if __name__ == '__main__':
p = Student()
p.input()
p.print()