TypeError: float() argument must be a string or a number, not 'list' python

Blazed

I have a problem with Python. This is my code:

def calcola():
            a = input()
            b = float(a[0].split("*"))
            c = float(a[0].split("/")) 
            d = float(a[0].split("-"))
            e = float(a[0].split("+"))
            j = float(a[1].split("*"))
            k = float(a[1].split("/")) 
            l = float(a[1].split("-")) 
            m = float(a[1].split("+")) 
            b = b[0]
            c = b[1]
            d = c[0]
            e = c[1]
            f = d[0]
            g = d[1]
            h = e[0]
            i = e[1]
            somma1 = b+c
            somma2 = d+e
            somma3 = f+g
            somma4 = h+i
            print(somma1)
            print(somma2)
            print(somma3)
            print(somma4)


calcola()

I've recieved some errors:

Traceback (most recent call last): File "file.py", line 29, in calcola() File "file.py", line 3, in calcola b = float(a[0].split("*")) TypeError: float() argument must be a string or a number, not 'list'

How can I transform the number in the list?

Moses Koledoye

You can't call float on a list directly. You can use map to call float on each item in the list. Like so:

b = map(float, a[0].split("*"))

In python 3.x

b = list(map(float, a[0].split("*")))

Or for more readability, use a list comprehension. Works for both python2 and python3:

b = [float(s) for s in a[0].split("*")]

But be sure the items after splitting are floatable

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: float() argument must be a string or a number in Django distance

From Dev

int() argument must be a string or a number, not 'SimpleLazyObject'

From Dev

Django TypeError int() argument must be a string or a number, not 'QueryDict'

From Dev

Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable'

From Dev

int() argument must be a string or a number, not 'builtin_function_or_method' - python

From Dev

TypeError: Must be String, not list

From Dev

Float must be a string or a number?

From Dev

TypeError: int() argument must be a string or a number, not 'Model Instance'

From Dev

TypeError: int() argument must be a string or a number, not 'datetime.datetime'

From Dev

TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'

From Dev

TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict' when creating a Token in Django

From Dev

Python: TypeError: argument after * must be a sequence

From Dev

TypeError: Float() argument must be a string or a number when reading a list()

From Dev

TypeError: Fetch argument has invalid type float32, must be a string or Tensor

From Dev

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

From Dev

TypeError: int() argument must be a string, a bytes-like object or a number, not 'DCountry'

From Dev

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

From Dev

TypeError: float() argument must be a string or a number, not 'Tensor'

From Dev

Python Pandas: Using a map function within a lambda / TypeError: ("int() argument must be a string, a bytes-like object or a number, not 'list'"

From Dev

TypeError: list indices must be integers, not float in heapsort

From Dev

int() argument must be a string or a number

From Dev

TypeError: Key id must be a string or a number

From Dev

TypeError: float() argument must be a string or a number with list sum

From Dev

int() argument must be a string or a number, not 'SimpleLazyObject' in django

From Dev

Python Float to String TypeError

From Dev

Django - TypeError: int() argument must be a string or a number, not 'dict'

From Dev

Getting "TypeError: float() argument must be a string or a number" with pandas plot()

From Dev

Django save to DB: TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'

From Dev

TypeError: float() argument must be a string or a number, not 'IntVar'

Related Related

  1. 1

    TypeError: float() argument must be a string or a number in Django distance

  2. 2

    int() argument must be a string or a number, not 'SimpleLazyObject'

  3. 3

    Django TypeError int() argument must be a string or a number, not 'QueryDict'

  4. 4

    Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable'

  5. 5

    int() argument must be a string or a number, not 'builtin_function_or_method' - python

  6. 6

    TypeError: Must be String, not list

  7. 7

    Float must be a string or a number?

  8. 8

    TypeError: int() argument must be a string or a number, not 'Model Instance'

  9. 9

    TypeError: int() argument must be a string or a number, not 'datetime.datetime'

  10. 10

    TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'

  11. 11

    TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict' when creating a Token in Django

  12. 12

    Python: TypeError: argument after * must be a sequence

  13. 13

    TypeError: Float() argument must be a string or a number when reading a list()

  14. 14

    TypeError: Fetch argument has invalid type float32, must be a string or Tensor

  15. 15

    TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

  16. 16

    TypeError: int() argument must be a string, a bytes-like object or a number, not 'DCountry'

  17. 17

    TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

  18. 18

    TypeError: float() argument must be a string or a number, not 'Tensor'

  19. 19

    Python Pandas: Using a map function within a lambda / TypeError: ("int() argument must be a string, a bytes-like object or a number, not 'list'"

  20. 20

    TypeError: list indices must be integers, not float in heapsort

  21. 21

    int() argument must be a string or a number

  22. 22

    TypeError: Key id must be a string or a number

  23. 23

    TypeError: float() argument must be a string or a number with list sum

  24. 24

    int() argument must be a string or a number, not 'SimpleLazyObject' in django

  25. 25

    Python Float to String TypeError

  26. 26

    Django - TypeError: int() argument must be a string or a number, not 'dict'

  27. 27

    Getting "TypeError: float() argument must be a string or a number" with pandas plot()

  28. 28

    Django save to DB: TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'

  29. 29

    TypeError: float() argument must be a string or a number, not 'IntVar'

HotTag

Archive