我正在學習Python和我爲什麼要在函數的相關章節,我寫代碼之一:Python的功能不起作用
import random
def roll(sides, dice):
result = 0
for rolls in range(0,dice):
result += random.randint(1, sides)
return result
,但是,當我試圖進入功能,這出現
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
roll()
TypeError: roll() takes exactly 2 positional arguments (0 given)
「我在功能上的章」在什麼書? – 2012-02-11 02:16:05
逐行瀏覽您的代碼。你認爲會發生什麼? – 2012-02-11 03:13:23