代码之家  ›  专栏  ›  技术社区  ›  Asharad

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

  •  -2
  • Asharad  · 技术社区  · 7 年前

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

    例子:

    86266 + (((168480 - 86266) / (703786 - 510531)) * (703765.0 - 510531))
    

    86266
    

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

    168471.066239
    

    Python中的计算出了什么问题?

    2 回复  |  直到 7 年前
        1
  •  7
  •   akash karothiya    7 年前

    大体上 Python 2.7 3.3 计算结果各不相同。

    Python 3.3返回 0.1 对于 1/10 0 __future__

    >>> from __future__ import division
    >>> print(86266 + (((168480 - 86266) / (703786 - 510531)) * (703765.0 - 510531)))
    168471.066239
    
        2
  •  -1
  •   seralouk    7 年前

    它与python版本和除法运算符有关

    示例:

    使用2.7:

    Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08)
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://anaconda.org
    
    x = 86266 + (((168480 - 86266) / (703786 - 510531)) * (703765.0 - 510531))
    
    print(x)
    
    
    86266.0
    

    使用python 3.3:

    x = 86266 + (((168480 - 86266) / (703786 - 510531)) * (703765.0 - 510531))
    
    print(x)
    
    168471.066239