[Tutor] Generating random in a user specified range.
nick at javacat.f2s.com
Tue Apr 27 12:20:52 EDT 2004
im not sure of line 'range = range()' .
That errors when I try it here at home.
Are you aware that range() is a built in keyword ?
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
Behalf Of Adam
Sent: 27 April 2004 14:22
To: tutor at python.org
Subject: [Tutor] Generating random in a user specified range.
I'm trying to develop an app where the user can specify the range in
which a random number will be generated from.
So far, I have two functions; range collects the range in which the
random number is to be generated from and generate number is the one
which creates the number. Range produces a list, which holds the top and
bottom number which is returned and then is passed to generatenumber to
create a number.
However, I seem to have a problem - I get an error using
random.randint(a,b) and with random.randrange(a,b). It seems that it
might be fussy accepting parts of a list as the argument. I've tried
converting them to integers and then passing the interger, but it still
Any advice on what I can do to fix this?
The driving code is:
range = range()
raw_input("click ok to carry ok")
target = generatenumber(range) #kicks the whole thing off
strtop = raw_input("What is your top number?")
strbottom = raw_input("What is your bottom number?")
top = int(strtop)
bottom = int(strbottom)
range = [bottom, top]
print "range top is ", range
print "range bottom is ", range
top = int (range)
bottom = int (range)
target = random.randrange(range, range) # and I've also tried
print "Target is ", target
ok = raw_input("please press enter to continue")
Tutor maillist - Tutor at python.org
More information about the Tutor