[解決]這是一個愚蠢的錯字。抱歉。Python骰子游戲錯誤
我目前正在學習python,並且遇到一些錯誤,如果你能指出我如何修復它們,以及爲什麼它們會是很好的錯誤,因爲我通過試驗和錯誤學習這樣的項目。 錯誤;
Would you like one or two die?2
Traceback (most recent call last):
File "diceRoller.py", line 34, in <module>
rollDice2();
File "diceRoller.py", line 18, in rollDice2
result = random.randrage(2,13)
AttributeError: 'module' object has no attribute 'randrage'
我的代碼;
import random
import time
numDice = input("Would you like one or two die?")
if (numDice == 1):
rollDice1();
else:
rollDice2();
def rollDice1():
result = random.randrange(1,7)
print ("It landed on..")
time.sleep(1)
print(result)
try:
answer = input("would you like to play again? [y/n]")
except:
pass
if answer in ('y','Y'):
return True
return False
def rollDice2():
result = random.randrange(2,13)
print ("It landed on..")
time.sleep(1)
print(result)
try:
answer= input("would you like to play again? [y/n]")
except:
pass
if answer in ('y', 'Y'):
return True
return False
while rollDice1 or rollDice2():
continue
這是一個錯字。它應該是:'result = random.randrange(2,13)' – bernie 2014-10-11 00:16:37
謝謝,我想它睡覺的時間都是這個問題嗎? – 2014-10-11 00:19:43
另外,我想你應該在調用它們之前先定義你的方法。並使用主要方法來測試它們。 – 2014-10-11 00:20:17