[Tutor] random number generator
Terry Carroll
carroll at tjc.com
Fri Oct 5 07:41:32 CEST 2007
On Thu, 4 Oct 2007, Jerry VanBrimmer wrote:
> I'm no Python wizard, I'm still learning myself. But I think you need
> another "if" statement to check if "guess" is equal to "number".
>
> if guess == number:
> print "Congratulations!"
No, he's got the equivalent function in his while statement:
while (guess != number):
The idea is to stay in the loop as long as they're UNequal, and then drop
out to the "Congratulations" part.
But comparing floats as equal or not equal is never a very robust idea.
http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
More information about the Tutor
mailing list