[Tutor] Data persistence problem

Peter Otten __peter__ at web.de
Fri Jun 21 13:10:16 CEST 2013


Alan Gauld wrote:

> rand_num = None
> 
> def rand_int():
>     global rand_num
>     if not rand_num:

This will not recognize the (unlikely but possible) case that 
random.random() returns 0.0. So you better check for None explicitly

      if rand_num is None:
>        rand_num = int(math.ceil (random.random()*1000))
>     return rand_num




More information about the Tutor mailing list