Skip to content

Commit 0dea049

Browse files
avychcclauss
andauthored
Added static type checking to polynom-for-points.py towards issue #2128 (#2335)
* Added static type checking to linear_algebra/src/polynom-for-points.py * Fixed TravisCI errors * Update polynom-for-points.py Co-authored-by: Christian Clauss <[email protected]>
1 parent 2de2267 commit 0dea049

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: linear_algebra/src/polynom-for-points.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
def points_to_polynomial(coordinates):
1+
from typing import List
2+
3+
4+
def points_to_polynomial(coordinates: List[List[int]]) -> str:
25
"""
36
coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
47
number of points you want to use
@@ -57,7 +60,7 @@ def points_to_polynomial(coordinates):
5760
while count_of_line < x:
5861
count_in_line = 0
5962
a = coordinates[count_of_line][0]
60-
count_line = []
63+
count_line: List[int] = []
6164
while count_in_line < x:
6265
count_line.append(a ** (x - (count_in_line + 1)))
6366
count_in_line += 1
@@ -66,7 +69,7 @@ def points_to_polynomial(coordinates):
6669

6770
count_of_line = 0
6871
# put the y values into a vector
69-
vector = []
72+
vector: List[int] = []
7073
while count_of_line < x:
7174
vector.append(coordinates[count_of_line][1])
7275
count_of_line += 1
@@ -80,7 +83,7 @@ def points_to_polynomial(coordinates):
8083
zahlen += 1
8184
if zahlen == x:
8285
break
83-
bruch = (matrix[zahlen][count]) / (matrix[count][count])
86+
bruch = matrix[zahlen][count] / matrix[count][count]
8487
for counting_columns, item in enumerate(matrix[count]):
8588
# manipulating all the values in the matrix
8689
matrix[zahlen][counting_columns] -= item * bruch
@@ -91,7 +94,7 @@ def points_to_polynomial(coordinates):
9194

9295
count = 0
9396
# make solutions
94-
solution = []
97+
solution: List[str] = []
9598
while count < x:
9699
solution.append(vector[count] / matrix[count][count])
97100
count += 1
@@ -100,7 +103,7 @@ def points_to_polynomial(coordinates):
100103
solved = "f(x)="
101104

102105
while count < x:
103-
remove_e = str(solution[count]).split("E")
106+
remove_e: List[str] = str(solution[count]).split("E")
104107
if len(remove_e) > 1:
105108
solution[count] = remove_e[0] + "*10^" + remove_e[1]
106109
solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count])

0 commit comments

Comments
 (0)