【发布时间】:2014-09-11 20:14:31
【问题描述】:
我的代码:
# -*- coding: utf-8 -*-
def dice():
import random
number = random.randint(1,6)
print "The dice shows:" + str(number)
[dice() for _ in range(3)]
示例结果:
The dice shows:2
The dice shows:4
The dice shows:3
如果我想对列表中的所有数字求和,我该怎么做? (在这种情况下,我会得到总和 9)
【问题讨论】:
-
使用
sum()。 (并且不要在函数中导入random)