1
- def points_to_polynomial (coordinates ):
1
+ from typing import List
2
+
3
+
4
+ def points_to_polynomial (coordinates : List [List [int ]]) -> str :
2
5
"""
3
6
coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
4
7
number of points you want to use
@@ -57,7 +60,7 @@ def points_to_polynomial(coordinates):
57
60
while count_of_line < x :
58
61
count_in_line = 0
59
62
a = coordinates [count_of_line ][0 ]
60
- count_line = []
63
+ count_line : List [ int ] = []
61
64
while count_in_line < x :
62
65
count_line .append (a ** (x - (count_in_line + 1 )))
63
66
count_in_line += 1
@@ -66,7 +69,7 @@ def points_to_polynomial(coordinates):
66
69
67
70
count_of_line = 0
68
71
# put the y values into a vector
69
- vector = []
72
+ vector : List [ int ] = []
70
73
while count_of_line < x :
71
74
vector .append (coordinates [count_of_line ][1 ])
72
75
count_of_line += 1
@@ -80,7 +83,7 @@ def points_to_polynomial(coordinates):
80
83
zahlen += 1
81
84
if zahlen == x :
82
85
break
83
- bruch = ( matrix [zahlen ][count ]) / ( matrix [count ][count ])
86
+ bruch = matrix [zahlen ][count ] / matrix [count ][count ]
84
87
for counting_columns , item in enumerate (matrix [count ]):
85
88
# manipulating all the values in the matrix
86
89
matrix [zahlen ][counting_columns ] -= item * bruch
@@ -91,7 +94,7 @@ def points_to_polynomial(coordinates):
91
94
92
95
count = 0
93
96
# make solutions
94
- solution = []
97
+ solution : List [ str ] = []
95
98
while count < x :
96
99
solution .append (vector [count ] / matrix [count ][count ])
97
100
count += 1
@@ -100,7 +103,7 @@ def points_to_polynomial(coordinates):
100
103
solved = "f(x)="
101
104
102
105
while count < x :
103
- remove_e = str (solution [count ]).split ("E" )
106
+ remove_e : List [ str ] = str (solution [count ]).split ("E" )
104
107
if len (remove_e ) > 1 :
105
108
solution [count ] = remove_e [0 ] + "*10^" + remove_e [1 ]
106
109
solved += "x^" + str (x - (count + 1 )) + "*" + str (solution [count ])
0 commit comments