swappo1
August 21st, 2008, 05:12 PM
Hello,
This morning I wrote the following program in python and it worked when I tried it.
#! /usr/bin/env python
# hilow.py
import random
number = random.randint(1, 100)
guess = 0
while guess != number:
guess = input("Guess a number between 1 and 100: ")
if guess < number:
print "The number is higher."
elif guess > number:
print "The number is lower."
print "You guessed the number. ", guess
I then experimented with random repeatedly and I have not been able to get anything with random to work. When I went back and tried my original program it now isn't working and I get the following:
scott@scott-laptop:~$ python hilow.py
Traceback (most recent call last):
File "hilow.py", line 4, in <module>
import random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/apport_python_hook.py", line 38, in apport_excepthook
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.5/site-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.5/site-packages/apport/report.py", line 14, in <module>
import subprocess, tempfile, os.path, urllib, re, pwd, grp, os, sys
File "/usr/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
Original exception was:
Traceback (most recent call last):
File "hilow.py", line 4, in <module>
import random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
scott@scott-laptop:~$
I am not sure whether it is something I am doing wrong or if it is python. I don't understand this last error. I appreciate any help you can provide.
This morning I wrote the following program in python and it worked when I tried it.
#! /usr/bin/env python
# hilow.py
import random
number = random.randint(1, 100)
guess = 0
while guess != number:
guess = input("Guess a number between 1 and 100: ")
if guess < number:
print "The number is higher."
elif guess > number:
print "The number is lower."
print "You guessed the number. ", guess
I then experimented with random repeatedly and I have not been able to get anything with random to work. When I went back and tried my original program it now isn't working and I get the following:
scott@scott-laptop:~$ python hilow.py
Traceback (most recent call last):
File "hilow.py", line 4, in <module>
import random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/apport_python_hook.py", line 38, in apport_excepthook
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.5/site-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.5/site-packages/apport/report.py", line 14, in <module>
import subprocess, tempfile, os.path, urllib, re, pwd, grp, os, sys
File "/usr/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
Original exception was:
Traceback (most recent call last):
File "hilow.py", line 4, in <module>
import random
File "/home/scott/random.py", line 8, in <module>
number = random.randrange(0, 5)
AttributeError: 'module' object has no attribute 'randrange'
scott@scott-laptop:~$
I am not sure whether it is something I am doing wrong or if it is python. I don't understand this last error. I appreciate any help you can provide.