форкнуто от main/python-labs
Родитель
af8459e14c
Сommit
a7341a4949
@ -0,0 +1,10 @@
|
|||||||
|
def mod1(filename):
|
||||||
|
numbers = []
|
||||||
|
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
for i in f:
|
||||||
|
stroka = i.strip().split()
|
||||||
|
for chiselki in stroka:
|
||||||
|
number = float(chiselki)
|
||||||
|
numbers.append(number)
|
||||||
|
return numbers
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
import statistics
|
||||||
|
|
||||||
|
def corrrr(list1, list2):
|
||||||
|
n = min(len(list1), len(list2))
|
||||||
|
if n == 0:
|
||||||
|
return 0.0
|
||||||
|
x = list1[:n]
|
||||||
|
y = list2[:n]
|
||||||
|
|
||||||
|
try:
|
||||||
|
correlation = statistics.correlation(x, y)
|
||||||
|
except statistics.StatisticsError:
|
||||||
|
correlation = 0.0
|
||||||
|
|
||||||
|
return correlation
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
import MODTASK1
|
||||||
|
import MODTASK2
|
||||||
|
|
||||||
|
file1 = input("Первый файл: ")
|
||||||
|
file2 = input("Второй файл: ")
|
||||||
|
|
||||||
|
list1 = MODTASK1.mod1(file1)
|
||||||
|
list2 = MODTASK1.mod1(file2)
|
||||||
|
|
||||||
|
result = MODTASK2.corrrr(list1, list2)
|
||||||
|
|
||||||
|
print(f"Коэффициент корреляции: {result:.3f}")
|
||||||
@ -0,0 +1 @@
|
|||||||
|
1 2 3 4 5 6 7 8 9 10
|
||||||
@ -0,0 +1 @@
|
|||||||
|
20 30 40 123456 789102213 70 80 90 100 110
|
||||||
Загрузка…
Ссылка в новой задаче