我遇到这个问题有一段时间了,似乎找不到任何有效的方法。我怎样才能得到它,以便当前空间增加滚动总量。def roll(): import random doubles = 0 x = random.randint(1, 6) y = random.randint(1, 6) print(x, y) if x == y: print('Doubles') doubles = 1 print(f'You have rolled {doubles} doubles!') x1 = random.randint(1, 6) y1 = random.randint(1, 6) print(x1, y1) if x1 == y1: print('Doubles') doubles = 2 print(f'You have rolled {doubles} doubles!') x2 = random.randint(1, 6) y2 = random.randint(1, 6) print(x2, y2) if x2 == y2: doubles = 3 print(f'You rolled {doubles} doubles!') print('Go to Jail!') else: total2 = x + y + x1 + y1 + x2 + y2 print(f'You rolled {total2} in total.') else: total1 = x + y + x1 + y1 print(f'You rolled {total1} in total.') else: total = x + y print(f'You rolled {total} in total.') currentspace = 0print(roll())
1 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
使用global
声明。
def roll(): global currentspace ...do your things... currentspace += 1
添加回答
举报
0/150
提交
取消