Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将如何:
编写一个函数,它接受一个整数参数,并返回一个包含 1 到 100 之间的随机数的列表。 使用这个函数,编写一个程序,将 50 个随机数存储在一个列表中,然后计算并打印出所有数字的平均值。
编写一个函数,它接受一个整数参数,并返回一个包含 1 到 100 之间的随机数的列表。
使用这个函数,编写一个程序,将 50 个随机数存储在一个列表中,然后计算并打印出所有数字的平均值。
下面是使用 numpy array 的解决方案:
import numpy as np def randomx(nb): random_array = np.random.randint(1, 100, nb) print mean(random_array)