TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
python, typeerror
Solution
The variable `astlist` is a list. You're adding `list1` to it several times which is also a list. But you're also adding a list to `list1` each time: `list1.append([x,y,z])`. So ultimately `astlist` is a list containing multiple lists which each contain a list with three integers.
So when you write `x,y,z=astlist[row]` the variables `x`, `y` and `z` are actually lists, not integers. This means you're trying to compute `x**2` but `x` is a list, not a number. This is why Python is giving you an error message as `**` doesn't support raising a list to a power.
I'm not sure what you're trying to accomplish with all these lists but you should change the code so that you're only trying to raise numbers to the power of two and not lists.
Problem
I'm trying to take the values from the previous function and use in another function. This is my first programming class and language, and i'm totally lost. I figured out how to take the variables from astlist and put them into the function distance, but now Python is telling me I can't use these variables in an equation because they're in a list now? Is that what it's saying? I'm also just printing the lists to see if they are running. These are two of my functions, and the functions are both defined in my main function. I'm taking these lists and eventually putting them into files, but I need to figure out why the equation isn't working first. Thanks! ``` def readast(): astlist = [] for j in range(15): list1 = [] for i in range(3): x = random.randint(1,1000) y = random.randint(1,1000) z = random.randint(1,1000) list1.append([x,y,z]) astlist.append(list1) print(astlist) return astlist def distance(astlist): distlist = [] for row in range(len(astlist)): x, y, z = astlist[row] x1 = x**2 y2 = y**2 z2 = z**2 equation = math.sqrt(x+y+z) distlist.append(equation) print(distlist) return distlist ```