python - Solving simple equation -


i have code:

tp = len(set1) fp = len(set2) fn = len(set3)  if fp == 0:     score = ((2*tp)/((2*tp)+fn))     print "warning: fp equal 0."  elif fn == 0:      score = ((2*tp)/((2*tp)+fp))      print "warning: fn equal 0"  elif tp == 0:     score = ((2*tp)/((2*tp)+fp+fn))     print "warning: tp equal 0"  else:     score = ((2*tp)/((2*tp)+fp+fn))  print " score = ", score 

but reason score returns 0 every time. checked values , seems correct. me??

because using integer division every time. instead of 2 constant use 2.0 force python's division return float.

ex:

score = ((2.0*tp)/((2.0*tp)+fn)) 

as side note can read more on forcing floating division in question: how can force division floating point? division keeps rounding down 0 , in docs: decimals, floats, , floating point arithmetic


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -