相关疑难解决方法(0)

强制Python计算为double

我想在Python中打印一个double.但它不起作用,我不知道为什么.

我的代码:

test = 3000 / (1500 * 2000)
print str(test)
Run Code Online (Sandbox Code Playgroud)

如果我做以下事情,我总是得到一个0而不是一个0.001:

test = 3000 / (1500 * 2000)
print '%.10f' % test
Run Code Online (Sandbox Code Playgroud)

我得到了一个0.000000000而不是0.001.

我怎么告诉Python这应该是双倍的?

python

1
推荐指数
1
解决办法
6628
查看次数

python简单百分比计算返回0

好吧,这似乎是微不足道的,但我无法弄清楚这一点.我需要做一个基本的百分比计算.这是我的代码:

corr = 205
score =  100 * (corr / 225 )
print score 
Run Code Online (Sandbox Code Playgroud)

但结果是0.怎么会?没有完全不同的方法来写这个,但我确实改变了这个并尝试添加int()s和float()s,但结果总是如此0.

python math integer division python-2.x

0
推荐指数
2
解决办法
1689
查看次数

它一直返回TypeError:需要一个float

我已经在这里阅读了类似的问题,但没有任何对我有用..这个python代码有什么问题..它一直返回这个错误信息:

TypeError:需要一个float

Beta = float( math.atan([(2 - yr)/(1 - xr)]))
print Beta;
Run Code Online (Sandbox Code Playgroud)

请注意: xr = 2,yr = 2是在代码的前一行之前预定义的

python floating-point

0
推荐指数
1
解决办法
1196
查看次数

python 2和3的相同代码给出不同的结果

我的问题是我在客户端上运行python 3,而执行程序的服务器运行了python 2。

因此,我设置了以下脚本:

from math import radians, cos, sin, asin, sqrt, exp
from datetime import datetime
def dateSmoother(a, b):
    #Format the date
    a = datetime.strptime(a, "%Y-%m-%d")
    b = datetime.strptime(b, "%Y-%m-%d")
    diff = (a-b).days

    return exp(-(diff/h_date)**2)

def timeSmoother(a, b):
    # Since we only got readings from two different times
    # We first check to see if they are the same
    if (a==b):
        return exp(-(0/h_time)**2)
    else:
        return exp(-(12/h_time)**2)


h_date = 30
h_time = 12
a = "2013-11-01"
b = "2013-11-13"
print(dateSmoother(a, …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x

0
推荐指数
1
解决办法
135
查看次数

在Python中无法将较小的数字除以较大的数字

在python中,我无法将5除以22。当我尝试使用它时,即使我使用float,它也给我零分!

>>> print float(5/22)
0.0
Run Code Online (Sandbox Code Playgroud)

python-2.7

-1
推荐指数
1
解决办法
2614
查看次数

为什么我从Python Interpreter(2.7.6)和计算器得到不同的结果?

我有以下公式:

SZT = SZ0 +(((SZ1-SZ0)/(WMZ1-WMZ0))*(WMZT-WMZ0))

例:

86266 + (((168480 - 86266) / (703786 - 510531)) * (703765.0 - 510531))
Run Code Online (Sandbox Code Playgroud)

当我使用python解释器(2.7.6)进行此计算时,我得到了这个结果:

86266
Run Code Online (Sandbox Code Playgroud)

当我使用计算器(例如谷歌)时,我得到了这个结果:

168471.066239
Run Code Online (Sandbox Code Playgroud)

我假设第二个是正确的结果.

Python中的计算有什么问题?

python calculation

-2
推荐指数
1
解决办法
114
查看次数