[Tutor] another for loop question - latin square
Alan Gauld
alan.gauld at btinternet.com
Mon Dec 31 01:51:07 CET 2012
On 31/12/12 00:27, Steven D'Aprano wrote:
> On 31/12/12 10:59, Brandon Merritt wrote:
>> I am having trouble figuring out a solution after a couple hours now of
>> playing with the code. I'm trying to make a latin square using the code
>> below:
I totally agree with everything Steven said.
However there is one glaring mistake in your code....
>> count = 0
>> while count< 8:
>> for i in firstrow:
>> print i
>> count += 1
>> firstrow[i+1]
What do you think that last row is doing?
Whatever it is, you are almost certainly wrong.
But eventually it is likely to throw an index error...
>> -----------------------------------------------------------------------
>>
>> It seemed like I could make the for loop work by doing something like
>> this:
>>
>> for i in firstrow:
>> print i, i+2
>>
>> but that obviously is not a solution either. Any ideas?
It works perfectly. It prints out i and i+2 for every member of
firstrow. Whether that's what you want to do is another matter.
As Steven said, try working out what you want to do first,
then write the code.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list