Search code examples
pythonerror-handlingfloating-pointdivision

float division error in python with variables


so I'm doing something really simple:

shared = sum*2.0/(totalCNV(CNVs1,str(chrom))+totalCNV(CNVs2,str(chrom)))

and I get this:

ZeroDivisionError: float division

So now I just want to make it a floating point division, but I don't know how to do that. Can I just convert all the variables to floating points? Any suggestions? Cheers!


Solution

  • The error you're getting implies that

    (totalCNV(CNVs1,str(chrom))+totalCNV(CNVs2,str(chrom)))
    

    is evaluating to zero, so when you try to do a division with that as the denominator, you're dividing by zero.

    If that error is unexpected, chances are there's a problem earlier in your code.