在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