When realising the following operation:

do = 1.0 - 2.718281828**(-(23**2)/730)
print do

Python returns 0.632120558766

When you do it on the calculator or when google it, it returns 0.515509538

:-O

>>> 1.0 - 2.718281828**(-(23.0**2)/730)
0.5155095380022271
>>> #Or import division from future
>>> from __future__ import division
>>> 1.0 - 2.718281828**(-(23**2)/730)
0.5155095380022271
>>>

http://www.ferg.org/projects/python_gotchas.html

"/ 730" has to be a float (or you have to convert somehow).

##1.0 - 2.718281828**(-(23**2)/730)
a = 23**2
print a
a *= -1
print a
print "---------------"
print a/730
a /= 730.0
print a
print "---------------"
b =  2.718281828**a
print b
print 1.0 - b

Something like
q = 3/5
would signify a division of integers and would give you
q = 0
in most computer languages and Python2

Python3 has changed this '/' is now a floating point division and '//' is an integer division.

If you want q to be a floating point in Python2, then you simply use
q = 3/5.0

print (23**2)/730     # 0
print (23**2)/730.0   # 0.724657534247

Oh... I though that using

.0

in only one element was enough. Tks

The compiler will take your math expression and turn it into a series of smaller stepwise expressions. That one time .0 can easily get lost. Anyway, Python3 takes care of that ambiguity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.