Answer the question
In order to leave comments, you need to log in
TypeError: 'float' object is not iterable, how to fix?
Traceback error (most recent call last):
File "main.py", line 20, in
D[i] += math.fabs(math.fabs(A[i][j]) - (A[i][j ])**2)
TypeError: 'float' object is not iterable
Help me fix
Code:
import math
A = []
n = 8
m = 7
A = [[n + m for m in range(m)] for n in range(n)]
D = [[n] for n in range(n)]
print("Array A:")
for i in range(0, n):
print()
for j in range(0, m):
A[i][j] = math.exp(i / (j + 1)) / (i + 1)
print("{:6.6f}".format(A[i][j]), end = " ")
print("\n")
print("All the distances:")
for i in range(n):
for j in range(m):
D[i] += math.fabs(math.fabs(A[i][j]) - (A[i][j])**2)
print("{:6.6f}".format(D[i]), end = " ")
print()
max = D[0]
maxI = 0
for i in range(n):
if D[i] > max:
max = D[i]
maxI = i
print("The biggest distance from first row is:", "{:6.6f}".format(max))
print("Index of this distance is:", maxI)
Answer the question
In order to leave comments, you need to log in
I don’t know if I think correctly, but why do you need += in the error line?
Is the following not correct?:
D[i] = math.fabs(math.fabs(A[i][j]) - (A[i][j])**2
This is what gave me:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question