random number between 0 and 20

P

Peter Hansen

How can I generate a random number between 0 - 20 and store the number
in nrrandom?

You would use the "random" module from the standard
library. It has a randint() method that should do
the job. Read the docs for more.

Assigning to nrrandom? Is that just a variable
name? Have you read the tutorial, which covers
basic things like assignment?

-Peter
 
A

aleksander.helgaker

How can I generate a random number between 0 - 20 and store the number
in nrrandom?
 
C

Christos TZOTZIOY Georgiou

How can I generate a random number between 0 - 20 and store the number
in nrrandom?

Just choose a random number yourself, eg. nrrandom=17 (just kidding :)


import random

nrrandom = random.randint(0,20)

See also the random.randrange function.
 
A

aleksander.helgaker

Yes I know about assigning and all that. I just stated the name of the
variable so that people could easily explain how to create the random
number. I needed it to practice Python. I just finished making a number
guess program. I just finished it. It was much easier to do then I
thought it would be.
 
C

Christos TZOTZIOY Georgiou

NNTP-Posting-Date: Wed, 20 Apr 2005 10:20:45 -0500
Date: Wed, 20 Apr 2005 11:10:21 -0400

Based on these headers from your message, plus the fact that you
answered five minutes before aleksander asked his question, you might
want to either check your computer clock for accuracy or return the time
machine to Guido...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top