0
我無法正確地返回答案。如何正確返回?
return roll_dice(x)
的語法是否正確,或者是否需要用括號中的其他內容替換x
?
我是初學者,想一些幫助,這個問題:
我的代碼:
import numpy as np
def roll_dice(x):
totmoney = 0
for a in range(x):
throw_one = np.random.randint(6)
throw_two = np.random.randint(6)
if throw_one % 2 != 0 or throw_two % 2 != 0:
totmoney += throw_one + throw_two
print throw_one,"|",throw_two,"|",totmoney
else:
totmoney -= throw_one + throw_two
print throw_one,"|",throw_two,"|",totmoney
return roll_dice(x)
'return roll_dice(x)'沒有break語句,不改變'x'的值會導致無限遞歸循環。你需要在你的方法中創建一個嵌套列表來代表矩陣,然後返回該變量作爲'return my_nested_list' – ZdaR
我該怎麼做呢? – ally1637