
我可以使用Excel找到它,但是我想知道如何使用Python来完成它。
我可以使用numpy创建一个正态分布。我创建了一个平均为80,sd为15的随机数,以及0至7 (1至6)之间的随机数。
import numpy as np
from decimal import *
total_num = 0
i=1
trial = 100
while i < trial:
rand_num =np.random.randint(1,7)
person = np.random.normal(80, 15)
total_weight = int(rand_num)*Decimal(person)
# print(total_weight)
if total_weight > int(500):
total_num += total_num
i += 1;
total_num/trial但是我的输出是0。我在这里做错什么了?
发布于 2019-06-02 02:12:36
我只需要修改total_num += 1。
import numpy as np
count = 0
i=int(1)
trial = int(10000)
limit = int(500)
while i < trial:
rand_num =np.random.randint(1,7)
person = np.random.normal(80, 15)
total_weight = int(rand_num)*person
# print(total_weight)
if total_weight > limit:
#print('yes')
count += 1
count
i += 1;
print("Probability is: ")
print(count/trial)https://stackoverflow.com/questions/56411662
复制相似问题