[Tutor] Random number generation

Kevin python_newbie at vedorian.com
Tue Aug 17 21:15:22 CEST 2004


Thats exactly what I was looking for thanks!!
----- Original Message -----
From: "Nick Lunt" <nick at javacat.f2s.com>
To: "Python Tutor" <tutor at python.org>
Sent: Tuesday, August 17, 2004 3:13 PM
Subject: RE: [Tutor] Random number generation


> Hi Kevin,
>
> with the minimal info you've supplied its not easy to be sure what you
want.
>
> Hows this look
>
> [code]
>
> from random import randrange
>
> rand = randrange(1, 1000)
> ans = raw_input('Enter an int from 1 to 1000: ')
>
> if int(ans) == rand:
>     print 'well done!'
> else:
>     print 'unlucky!'
>
> [/code]
>
> This will need to some error trapping in case the user enters a letter for
> example, also a while loop would be handy so the user has more than one
> guess ;)
>
> This might help http://docs.python.org/tut/node6.html
>
> Hope that helps
> Nick.
>
>
>
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On Behalf
Of
> Kevin
> Sent: 17 August 2004 19:42
> To: Python
> Subject: [Tutor] Random number generation
>
>
> I am trying to make a simple number guessing game. The only thing that I
> can't figure out so far is how to get the program to pick a random number?
>
> Thanks
>
> Kevin
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/04
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.726 / Virus Database: 481 - Release Date: 7/22/04



More information about the Tutor mailing list