@@ -3,30 +3,36 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
33 coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
44 number of points you want to use
55
6- >>> print( points_to_polynomial([]) )
6+ >>> points_to_polynomial([])
77 Traceback (most recent call last):
88 ...
99 ValueError: The program cannot work out a fitting polynomial.
10- >>> print(points_to_polynomial([[]]))
10+ >>> points_to_polynomial([[]])
11+ Traceback (most recent call last):
12+ ...
13+ ValueError: The program cannot work out a fitting polynomial.
14+ >>> points_to_polynomial([[1, 0], [2, 0], [3, 0]])
15+ 'f(x)=x^2*0.0+x^1*-0.0+x^0*0.0'
16+ >>> points_to_polynomial([[1, 1], [2, 1], [3, 1]])
17+ 'f(x)=x^2*0.0+x^1*-0.0+x^0*1.0'
18+ >>> points_to_polynomial([[1, 3], [2, 3], [3, 3]])
19+ 'f(x)=x^2*0.0+x^1*-0.0+x^0*3.0'
20+ >>> points_to_polynomial([[1, 1], [2, 2], [3, 3]])
21+ 'f(x)=x^2*0.0+x^1*1.0+x^0*0.0'
22+ >>> points_to_polynomial([[1, 1], [2, 4], [3, 9]])
23+ 'f(x)=x^2*1.0+x^1*-0.0+x^0*0.0'
24+ >>> points_to_polynomial([[1, 3], [2, 6], [3, 11]])
25+ 'f(x)=x^2*1.0+x^1*-0.0+x^0*2.0'
26+ >>> points_to_polynomial([[1, -3], [2, -6], [3, -11]])
27+ 'f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0'
28+ >>> points_to_polynomial([[1, 5], [2, 2], [3, 9]])
29+ 'f(x)=x^2*5.0+x^1*-18.0+x^0*18.0'
30+ >>> points_to_polynomial([[1, 1], [1, 2], [1, 3]])
31+ 'x=1'
32+ >>> points_to_polynomial([[1, 1], [2, 2], [2, 2]])
1133 Traceback (most recent call last):
1234 ...
1335 ValueError: The program cannot work out a fitting polynomial.
14- >>> print(points_to_polynomial([[1, 0], [2, 0], [3, 0]]))
15- f(x)=x^2*0.0+x^1*-0.0+x^0*0.0
16- >>> print(points_to_polynomial([[1, 1], [2, 1], [3, 1]]))
17- f(x)=x^2*0.0+x^1*-0.0+x^0*1.0
18- >>> print(points_to_polynomial([[1, 3], [2, 3], [3, 3]]))
19- f(x)=x^2*0.0+x^1*-0.0+x^0*3.0
20- >>> print(points_to_polynomial([[1, 1], [2, 2], [3, 3]]))
21- f(x)=x^2*0.0+x^1*1.0+x^0*0.0
22- >>> print(points_to_polynomial([[1, 1], [2, 4], [3, 9]]))
23- f(x)=x^2*1.0+x^1*-0.0+x^0*0.0
24- >>> print(points_to_polynomial([[1, 3], [2, 6], [3, 11]]))
25- f(x)=x^2*1.0+x^1*-0.0+x^0*2.0
26- >>> print(points_to_polynomial([[1, -3], [2, -6], [3, -11]]))
27- f(x)=x^2*-1.0+x^1*-0.0+x^0*-2.0
28- >>> print(points_to_polynomial([[1, 5], [2, 2], [3, 9]]))
29- f(x)=x^2*5.0+x^1*-18.0+x^0*18.0
3036 """
3137 if len (coordinates ) == 0 or not all (len (pair ) == 2 for pair in coordinates ):
3238 raise ValueError ("The program cannot work out a fitting polynomial." )
0 commit comments