![]() |
TypeError: float() argument must be a string or a number, not 'list' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: float() argument must be a string or a number, not 'list' (/thread-37617.html) |
TypeError: float() argument must be a string or a number, not 'list' - Anldra12 - Jul-01-2022
ef generateK(pShares, x_subi, Subset, q): y_subset = [] x_subset = [] Subset.sort() for ID in Subset: y_i = pShares[ID] x_i = x_subi[ID] y_subset.append(y_i) x_subset.append(x_i) recoveredK = 0 for j in range(1, (len(x_subset))): x_j = x_subset[j] b_j = 1 for L in range(1, len(x_subset)): if (L != j): x_L = x_subset[L] newCoeff = float(x_L)/(x_L - x_j) b_j = b_j * newCoeff recoveredK += y_subset[j] * (b_j) recoveredK_int = int(round(recoveredK)) print(" The secret value recovered k:", recoveredK_int) return recoveredK_int
RE: TypeError: float() argument must be a string or a number, not 'list' - BashBedlam - Jul-01-2022 If you plug-in these values and call your function generateK ([1, 2, 3], [1, 2, 3], [1, 2], 1)then it works as expected like so. It would seem that the problem is somewhere else in you code.
RE: TypeError: float() argument must be a string or a number, not 'list' - deanhystad - Jul-01-2022 To debug I would set a breakpoint and look at the arguments. If you don't have debugging you can use print. print(x_L, x_j) newCoeff = float(x_L)/(x_L - x_j)One of these will be a list. Knowing which will direct where you put the next print statement. |