def wordjumble(Wordlist, Hintlist, score):
wordchoice = getword(Wordlist, Hintlist)
high = len(wordchoice)
low = -len(wordchoice)
for i in range(10):
position = random.randrange(high,low)
print wordchoice[position]
score = wordguess(wordchoice, score)
return score
我收到一個值錯誤,我的任務是得到一個高位和低位之間的隨機數。 我的錯誤在哪裏?ValueError in random.randrange
這裏是回溯:
Traceback (most recent call last):
File "E:\Programming\Python\Worksheet 15\test.py", line 54, in
wordjumble(Wordlist, Hintlist, score)
File "E:\Programming\Python\Worksheet 15\test.py", line 49, in wordjumble
position = random.randrange(high,low)
File "E:\Portable Python 2.7.2.1\App\lib\random.py", line 217, in
randrange raise ValueError, "empty range for randrange() (%d,%d, %d)"
% (istart, istop, width) ValueError: empty range for randrange() (7,-7, -14)
是,其中*是*你的錯誤? :-) ..你能提供你得到的Traceback /錯誤信息嗎? – Levon
閱讀[random.randrange](http://docs.python.org/library/random.html#random.randrange)的文檔。 –
回溯(最近呼叫最後): 文件「E:\ Programming \ Python \ Worksheet 15 \ test.py」,第54行,在 wordjumble(Wordlist,Hintlist,score) 文件「E:\ Programming \ Python \ Worksheet 15 \ test.py「,第49行,wordjumble position = random.randrange(high,low) 文件」E:\ Portable Python 2.7.2.1 \ App \ lib \ random.py「,第217行,in randrange raise ValueError,「randrange()(%d,%d,%d)的空範圍」 ValueError:randrange()(7,-7,-14)的空範圍 –
Geostigmata