這是我的測試代碼(Python的3.2)這個Python錯誤是什麼意思?
import random
def singleMatch():
a = random.randint(1, 5050)
b = random.randint(1, 5050-a)
c = 5050-a-b
h = [a, b, c]
print(h)
computer = [841, 842, 3367]
score = 0
for i, j in zip(computer, h):
if i > j:
score = score + 1
if score == 2:
return 1
else:
return 0
def match(n):
matchScore = 0
for i in range(n):
s = singleMatch()
matchScore = matchScore + s
return matchScore
x = match(10000)
print(x)
當我運行代碼,我有時會收到此錯誤:
Traceback (most recent call last):
File "D:\Ercan\blotto.py", line 32, in <module>
x = match(10000)
File "D:\Ercan\blotto.py", line 28, in match
s = singleMatch()
File "D:\Ercan\blotto.py", line 5, in singleMatch
b = random.randint(1, 5050-a)
File "C:\Python32\lib\random.py", line 215, in randint
return self.randrange(a, b+1)
File "C:\Python32\lib\random.py", line 193, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (1,1, 0)
我無法弄清楚這是什麼意思,或者我做錯了。
謝謝。現在我想知道,爲什麼我是「那個」愚蠢的。 – blackened 2011-12-19 15:04:28