[Tutor] My number-guessing program

Luke Paireepinart rabidpoobear at gmail.com
Mon Oct 2 15:24:48 CEST 2006


>
>
> My line: number = 3
> Would I use 'number = random.randint()' in place of that, to have the 
> relevant number be random?
yes, but remember that random.randint takes 2 arguments, the endpoints.
E.G.
random.randint(1,10)
would be equivalent to
random.choice(range(1,11))
or
random.choice([1,2,3,4,5,6,7,8,9,10])

Note that the random.randint function includes both endpoints (I.E. the 
numbers are 1-10 including 10)
but the range() function doesn't include the last endpoint.
HTH
-Luke


More information about the Tutor mailing list