Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'random' is not defined [closed]

Here is my code:

r = random.randint(1,10)

But for some reason it's giving me the error

NameError: name 'random' is not defined

Other info: Mac, Python, 3.4.0 pylauncher

like image 857
user3430541 Avatar asked Mar 23 '14 20:03

user3430541


2 Answers

You have to import the module random:

import random

r = random.randint(1,10)
# ...
like image 159
Christian Tapia Avatar answered Sep 21 '22 00:09

Christian Tapia


>>> import random
>>> r = random.randint(1,10)
>>> r
10
like image 39
inspectorG4dget Avatar answered Sep 19 '22 00:09

inspectorG4dget