Float + min/max?
Shu-Hsien Sheu
sheu at bu.edu
Tue Aug 19 21:55:30 EDT 2003
Hi,
I am new to Python, and just wrote a small program to generate the maximum
number of the cartisian coordinates among all atoms in a given molecule.
However, I found the float function, if combined with max function, to be
kind of confusing. It would give a number with uneccessary decimals from
nowhere.
Not converting to float:
x = []
for i in (0, length-2):
slines[i] = lines[i].split()
if slines[i][0] == "ATOM":
x.append(slines[i][6])
print "xmax = " + max(x) + " " + "xmin = " + min(x)
Output:
xmax = 90.179 xmin = 64.112
Converting to float numbers:
x = []
for i in (0, length-2):
slines[i] = lines[i].split()
if slines[i][0] == "ATOM":
x.append( float(slines[i][6]) )
print "xmax = " + max(x) + " " + "xmin = " + min(x)
Output:
xmax = 90.179000000000002 xmin = 64.111999999999995
The original data file apparantly does not have those decimals. May I ask
how does it happend? Thank!
-shuhsien
More information about the Python-list
mailing list