randint() help

I'm having a very hard time getting the randint() to work.

I'm writing a program that would use the randint() function, but I can't get it to work.

There are 60 possible values, so in the beginning I have it set as randint(1, 60).

Then, when I need it to be used, I do the following:

if randint(1):
variable = "whatever"

elif randint(2):
variable = "whatever"

etc etc etc

But this gives me the following error:
NameError: name 'randint' is not defined

and I have the from random import random at the beginning.

Any reason this shouldn't work?

Comments

  • : I'm having a very hard time getting the randint() to work.
    :
    : I'm writing a program that would use the randint() function, but I can't get it to work.
    :
    : There are 60 possible values, so in the beginning I have it set as randint(1, 60).
    :
    : Then, when I need it to be used, I do the following:
    :
    : if randint(1):
    : variable = "whatever"
    :
    : elif randint(2):
    : variable = "whatever"
    :
    : etc etc etc
    :
    : But this gives me the following error:
    : NameError: name 'randint' is not defined
    :
    : and I have the from random import random at the beginning.
    :
    : Any reason this shouldn't work?
    :

    The reason it doesn't work is because you're not importing randint. You need this:

    from random import randint
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion