python标准化输出十进制_无法输出十进制近似值; Python 2将除法舍入为0或1

所以我决定制作一个超几何分布计算器(概率和统计数据)。问题是输出总是在0和1之间。所以根据输出值的不同,Python会舍入到0或1。

这是我的代码

from combinatorics import combination

from combinatorics import permutation

from factorial import factorial

from decimal import Decimal

#Hypergeometric and Binomial Distributions!

def hypergeometric(N, n, r, k):

hyper = (combination(r, k) * combination(N - r, n - k))/(combination(N, n))

return hyper

pop = int(raw_input("What is the size of the population? "))

draws = int(raw_input("How many draws were there? "))

spop = int(raw_input("What is the smaller population? "))

success = int(raw_input("How many successes were there? "))

print Decimal(hypergeometric(pop, draws, spop, success))我已经尝试导入十进制模块,但我不确定是否正确使用了它,或者如果那是甚至它在那里。任何帮助都是极好的!

编辑:例如,当我设置N = 15,n = 6,r = 5和k = 3时,它将答案舍入为0.我希望它打印正确的答案:.2397802398。谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值