I am following a Python textbook and it contains an error in a sample program below:
# Random Access
# Demonstrates string indexing
import random
word = "index"
print "The word is:", word, "\n"
high = len(word)
low = -len(word)
for i in range(10):
position = random.randrange(low, high)
print "word[", position, "]\t", word[position]
raw_input("\n\nPress enter to exit.")
Python complains with the following error:
File "C:\Python27\random.py", line 3, in <module>
import random
File "C:\Python27\random.py", line 11, in <module>
position = random.randrange(low, high) AttributeError: 'module' object has
no attribute 'randrange'
Any ideas how to fix this? I am new to programming and python. I have used the "import random" code before and it worked fine.