Support Forums
[SOLVED] print a random variable? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: [SOLVED] print a random variable? (/showthread.php?tid=1244)



[SOLVED] print a random variable? - nevets04 - 10-11-2009

I want to print either a b or c randomly
someone told me it was like this
import random
array = ['a','b','c','d','e','f']
random = random.choice(array)
print (random)
however I get this error when I do that
Quote:Traceback (most recent call last):
File "random.py", line 2, in <module>
random = random.choice(array)
NameError: name 'random' is not defined
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 38, in apport_excepthook
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.6/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.6/dist-packages/apport/report.py", line 14, in <module>
import subprocess, tempfile, os.path, urllib, re, pwd, grp, os, sys
File "/usr/lib/python2.6/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/home/nevets04/random.py", line 2, in <module>
random = random.choice(array)
NameError: name 'random' is not defined

Original exception was:
Traceback (most recent call last):
File "random.py", line 2, in <module>
random = random.choice(array)
NameError: name 'random' is not defined

SOLVED: Thanks to bsdpunk and fallen, we were able to figure out, that by changing the name of the program. It worked.


RE: print a random variable? - Nyx- - 10-11-2009

lol printin modules since day 1 son

Code:
import random
array = ['a','b','c','d','e','f']
r4nd0m = random.choice(array)
print (r4nd0m)

IDLE Wrote:>>> import random
>>> array = ['a','b','c','d','e','f']
>>> r4nd0m = random.choice(array)
>>> print(r4nd0m)
c



RE: print a random variable? - nevets04 - 10-11-2009

(10-11-2009, 06:01 PM)Nyx- Wrote: lol printin modules since day 1 son

Code:
import random
array = ['a','b','c','d','e','f']
r4nd0m = random.choice(array)
print (r4nd0m)

I get that error posted above when I import random