[Tutor] Random number generation
Nick Lunt
nick at javacat.f2s.com
Tue Aug 17 21:13:40 CEST 2004
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
More information about the Tutor
mailing list