I am an newbie in python, while running this code it gives me this error "TypeError: 'int' object is not iterable" in line 14. Please let me know my mistake.
x=int(raw_input())
y=int(raw_input())
z=int(raw_input())
n=int(raw_input())
xarr = [ i for i in range(x+1) ]
yarr = [ j for j in range(y+1) ]
zarr = [ k for k in range(z+1) ]
results = []
for i in xarr:
for j in yarr:
for k in zarr:
results.append([i,j,k])
for w in range(len(results)+1):
if (sum(w) != n):
results=results.append(sum(w))
print results
if x=1, y=1, z=1 and n=2 then results = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] and I am checking sum of each index of the list results and if the (sum==n) then do not add that index in results list
So output should be : [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
wis an integer, and you can't callsum()on an integer; what would it sum? It's not clear what you're trying to do, though; you should state what you expect the result to be.n? That'd be[0, 1, 2, 4, 7]for your sample.