Python Forum
TypeError: float() argument must be a string or a number, not 'list'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: float() argument must be a string or a number, not 'list'
#1

  1. I am working on project Shamir secret sharing scheme get the error
TypeError: float() argument must be a string or a number, not 'list'
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
Error:
Enter list of Participant i secrets 10 1 3 16 Traceback (most recent call last): File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 276, in <module> runPackage([], []) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 260, in runPackage predefinedVars, returnK = initiateScheme(predefinedVars) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 57, in initiateScheme recovered_k = runScheme(t, n, secret_k, q, Field) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 144, in runScheme generatedK = tryAccessStructure(k, pShares, x_subi, t_str, q) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 169, in tryAccessStructure generatedK = generateK(pShares, x_subi, P_Subset, q) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 249, in generateK newCoeff = float(x_L)/(x_L - x_j) TypeError: float() argument must be a string or a number, not 'list
Reply
#2
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.
Output:
The secret value recovered k: 3
It would seem that the problem is somewhere else in you code.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,184 Jun-09-2023, 06:56 PM
Last Post: kpatil
Question Extracting Version Number from a String britesc 2 1,030 May-31-2023, 10:20 AM
Last Post: britesc
  Formatting float number output barryjo 2 879 May-04-2023, 02:04 PM
Last Post: barryjo
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,049 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  convert string to float in list jacklee26 6 1,820 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 1,931 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable #1 isdito2001 1 1,046 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,375 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  TypeError: string indices must be integers JonWayn 12 3,263 Aug-31-2022, 03:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020