add new task
This commit is contained in:
parent
cd60369b65
commit
e5e17f9b2e
25
practica/stepik/stepik_tasks/test.py
Normal file
25
practica/stepik/stepik_tasks/test.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
def find_average(x):
|
||||||
|
return sum(x) / len(x)
|
||||||
|
|
||||||
|
med = 0
|
||||||
|
math = [] #математика
|
||||||
|
ph = [] #физика
|
||||||
|
ru = [] # русский
|
||||||
|
with open ('text.txt', 'r', encoding='utf-8') as f, open ('test.txt', 'w', encoding='utf-8') as f1:
|
||||||
|
lines = [line.split() for line in f]
|
||||||
|
li = 0 #кол-во строк
|
||||||
|
for i in lines:
|
||||||
|
for parts in i:
|
||||||
|
li+=1 #кол-во строк
|
||||||
|
y = parts.split(';') #
|
||||||
|
med = [int(y[1]),int(y[2]),int(y[3])] # среднее арифметическое каждого ученика
|
||||||
|
a = [int(item) for item in med]
|
||||||
|
f1.write(str(find_average(a)) + '\n')
|
||||||
|
math += [int(y[1])]
|
||||||
|
ph += [int(y[2])]
|
||||||
|
ru += [int(y[3])]
|
||||||
|
f1.write(' '.join([(str(find_average(math))), (str(find_average(ph))),(str(find_average(ru)))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user