[Tutor] random number generator

Terry Carroll carroll at tjc.com
Fri Oct 5 07:38:58 CEST 2007


On Thu, 4 Oct 2007, Jim Hutchinson wrote:

>  Any idea what I'm doing wrong? 

> while (guess != number):

This is your problem.  Like all^h^h^h most numbers in computing, floating
point numbers are stored in binary.  They only approximate the decimal
values they print out as.

Two numbers can print as the same value but actually have different 
values.

If you want to see if the numbers are identical to 10 decimal places, use 
this instead:

while (abs(guess-number) > 0.0000000001):




More information about the Tutor mailing list