我几乎做到了,但我的代码不起作用,我不明白为什么:
dice1 = 1
listofallcombinations = []
while dice <= 6:
dice2 = 1
while dice2 <= 6:
listofallcombinations.append((dice1,dice2))
dice2 = dice2 + 1
dice1 = dice1 + 1
sumof2dice = []
sumation = 2
while sumation <= 12:
sumof2dice[str(sumation)] = []
sumation = sumation + 1
for i in listofallcombinations:
sumofdice = 2
while sumofdice <= 12:
if i[0] + i[1] == sumofdice:
sumof2dice{str{sumofdice)).append(i)
sumofdice = sumofdice + 1
for i in sumof2dice
print i, "\n", sumof2dice[i], "\n"
我得到的错误是:
sumof2dice{str{sumofdice)).append(i)
有语法错误,但我不知道如何修复它。
谢谢!