[Tutor] trying to generate change in print output

Steven D'Aprano steve at pearwood.info
Sun Nov 7 23:26:34 CET 2010


Terry Green wrote:
> Am stumped, when I use this code:
> 
> race=int(row[2])
>     raceChek=1

This causes IndentationError: unexpected indent.

>     if raceChek == race: print ('raceChek ', raceChek, 'race ', race)
>     else: print ('raceChek ', raceChek,' no match ', 'race ', race);
> raceChek = race

> I Get this:
> 
> raceChek  1 race  1
> raceChek  1 race  1
> raceChek  1 race  1
[...]

I don't see how. The code you show fails completely, due to the 
inconsistent indentation. Even if we fix the indentation, it will only 
print something *once*, not eighteen times.

You don't show us what the variable "row" has, so we don't know what 
value "race" has. Presumably it equals 1, but then later on you get:

> raceChek  1  no match  race  2
[repeated many times]
> raceChek  1  no match  race  3
[repeated many times]

So mysteriously race is changing value.

Obviously you are not showing us the actual code you are running, but 
only part of the code. Would you like us to guess what code you are running?


> Seems my test between race and raceChek doesn't work!   What is wrong?

What makes you think that the problem is the test? It seems to me that 
the test

if raceChek == race:

is so simple that it couldn't possibly be broken. The problem is 
probably somewhere else. But since I don't know how you are getting 
eighteen lines of output, I don't know what you are doing and can't tell 
you what it is that is wrong.



-- 
Steven


More information about the Tutor mailing list