[Tutor] (no subject)

Pijus Virketis virketis@post.harvard.edu
Thu, 8 Aug 2002 09:44:39 +0300


Steve,

>I have sorted it now thanks to all your help and just to give=
 you 
>all a good laugh I thought id show you how not to do it.

[bits of steve's code]

password !=3D "steve":
count < max   

[/ bits of steve's code]

Actually, you were not too far off, and the only major problem=
 can be 
seen in the two lines above. In both cases, you perform a boolean=
 
operation, and then throw away the results without using them in=
 a 
conditional, or some other way. 

>>> 1 < 2
1

I have just asked the Python interpreter to tell me whether 1 is=
 less 
than 2, and it replied "True", or "1". When you write "count <=
 max", 
exactly the same thing happens, Python compares the values which=
 are 
assigned to variables "count" and "max" at the moment, and=
 returns 
either "1" or "0". Ditto for "password !=3D 'steve'". 

The way it's written in your code, Python sees something like=
 this:

# some code 
1 # result of evaluating the conditional 
# some more code 

You want to use this result in some productive way, not just=
 discard 
it. In your case, that means in a conditional. For instance:

>>> while password !=3D "steve": pass

Let's say "password" was assigned the value "pijus". Python would=
 
take two steps in evaluating the line above:

1) is "pijus" NOT EQUAL "steve" ? --> return "True"
2) WHILE True --> carry out the commands, i.e. pass

I hope this makes the use of boolean operations and conditionals=
 a 
little bit clearer. Don't hesitate to ask for a better=
 explanation. 
And I don't think anyone's laughing at you; I know that I have=
 done 
precisely the same thing when I started out with programming. ;)

Cheers, 

Pijus

-- 
"Anyone attempting to generate random numbers by deterministic=
 means 
is, of course, living in a state of sin." -- John Von Neumann