在python中导致这个错误的原因是什么?Python错误'str'对象没有属性'randrange'
Traceback (most recent call last):
File "F:/coding/python/python programming for absolute beginners/chapter 4/
The Jumble Game.py", line 9, in <module>
p=random.randrange(len(word))
AttributeError: 'str' object has no attribute 'randrange'
代码:
import random
print"\t\t\tThe Jumble Game"
print"In this program you will be given a jumble word and you have to guess that word"
set=("book","parrot","rabbit")
word=random.choice(set)
random=""
jumble=""
while(word):
p=random.randrange(len(word))
random=random+word[position]
word=word[:position]+word[(position+1):]
print("The jumble word is",random)
你使用空字符串变量遮盖随机模块。 – 2014-12-04 16:45:08
@EricLeschinski:不,名称在相同的范围内只是*反弹*。 – 2014-12-04 16:52:39