Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] print a random variable?
#1
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.
Reply
#2
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
[Image: sig.php]
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display variable serial data on Tkinter window. srinivas.rambha 0 1,010 06-17-2013, 05:54 AM
Last Post: srinivas.rambha
  [SOLVED]Referenced before assignment? uber1337 1 1,606 04-05-2010, 06:17 PM
Last Post: Fallen
  Why are there spaces when I do print x,x,x? nevets04 3 1,031 10-31-2009, 06:32 PM
Last Post: nevets04

Forum Jump:


Users browsing this thread: 1 Guest(s)