Hi there, I am having a little problem with my code here. The code that I have written is to take sample data such as:
0 0 0 0 1 0 1 0
0 0 1 0 0 1 0 1
1 0 0 0 1 0 0 1
1 0 0 0 1 1 0 1
1 1 0 0 0 1 1 0
0 1 1 0 1 0 0 1
1 1 1 0 0 1 0 0
0 1 0 1 1 0 1 0
0 1 1 1
0 0 1 0
1 0 0 1
0 1 0 0
0 1 1 0
1 0 1 0
0 0 0 0
1 0 0 0
0 1 1
1 0 0
1 0 0
END
and output this:
0: 4 6
1: 2 5 7
2: 0 4 7
3: 0 4 5 7
4: 0 1 5 6
5: 1 2 4 7
6: 0 1 2 5
7: 1 3 4 6
0: 1 2 3
1: 2
2: 0 3
3: 1
0: 1 2
1: 0 2
2:
3: 0
0: 1 2
1: 0
2: 0
The point of the code is to take any amount of input, however the input will always be square meaning that if the length of the first input is 5 then the first five lines of input should be considered as a single cycle. Sorry if I am not explaining this properly but a quick scan at the sample input and output will make perfect sense of it.
My code is breaking down at the point:
and python is giving the error:
Any help would be greatly appreciated!
Thanks
0 0 0 0 1 0 1 0
0 0 1 0 0 1 0 1
1 0 0 0 1 0 0 1
1 0 0 0 1 1 0 1
1 1 0 0 0 1 1 0
0 1 1 0 1 0 0 1
1 1 1 0 0 1 0 0
0 1 0 1 1 0 1 0
0 1 1 1
0 0 1 0
1 0 0 1
0 1 0 0
0 1 1 0
1 0 1 0
0 0 0 0
1 0 0 0
0 1 1
1 0 0
1 0 0
END
and output this:
0: 4 6
1: 2 5 7
2: 0 4 7
3: 0 4 5 7
4: 0 1 5 6
5: 1 2 4 7
6: 0 1 2 5
7: 1 3 4 6
0: 1 2 3
1: 2
2: 0 3
3: 1
0: 1 2
1: 0 2
2:
3: 0
0: 1 2
1: 0
2: 0
The point of the code is to take any amount of input, however the input will always be square meaning that if the length of the first input is 5 then the first five lines of input should be considered as a single cycle. Sorry if I am not explaining this properly but a quick scan at the sample input and output will make perfect sense of it.
My code is breaking down at the point:
Code:
if i[j] == '1':
Code:
Traceback (most recent call last):
File "D:\other py\lab11.py", line 7, in <module>
if i[j] == '1':
TypeError: 'int' object is unsubscriptable
Code:
inpt = raw_input().split() while inpt != 'END': count = len(inpt) for i in range(0,count): outpt = str(i) + ':' for j in range(0,count): if i[j] == '1': outpt = outpt + ' ' + j inpt = raw_input().split()
Thanks
Comment