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