generated from justuser-31/code_projects_template
Решения на первый блок
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
[
|
||||
{
|
||||
"name": "Иван Иванов",
|
||||
"age": 21,
|
||||
"grades": {
|
||||
"math": 85,
|
||||
"physics": 90,
|
||||
"history": 78
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Мария Петрова",
|
||||
"age": 22,
|
||||
"grades": {
|
||||
"math": 92,
|
||||
"physics": 88,
|
||||
"history": 80
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Алексей Смирнов",
|
||||
"age": 23,
|
||||
"grades": {
|
||||
"math": 75,
|
||||
"physics": 84,
|
||||
"history": 79
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,31 @@
|
||||
from json import loads
|
||||
|
||||
with open('data.json', 'r') as f:
|
||||
raw_data = f.read()
|
||||
f.close()
|
||||
data = loads(raw_data)
|
||||
|
||||
# Data for further analyze
|
||||
stud_i = []
|
||||
stud_score = []
|
||||
|
||||
stud_80_plus = []
|
||||
for i in range(len(data)):
|
||||
stud_i.append(i)
|
||||
average_score = (data[i]['grades']['math'] + data[i]['grades']['physics'] + data[i]['grades']['history'])/3
|
||||
stud_score.append(average_score)
|
||||
if data[i]['grades']['math'] > 80:
|
||||
stud_80_plus.append(i)
|
||||
|
||||
average_best = max(stud_score)
|
||||
aver_i = stud_score.index(average_best)
|
||||
aver = data[aver_i]
|
||||
|
||||
print(f'''Student with best average score:
|
||||
{aver['name']} {aver['age']} {aver['grades']['math']}-{aver['grades']['physics']}-{aver['grades']['history']}
|
||||
''')
|
||||
|
||||
print('Students with 80+ math scores:')
|
||||
for i in stud_80_plus:
|
||||
stud = data[i]
|
||||
print(f'''{stud['name']} {stud['age']} {stud['grades']['math']}-{stud['grades']['physics']}-{stud['grades']['history']}''')
|
||||
Reference in New Issue
Block a user