In the following code, I want to calculate the percent of G and C characters in a sequence. In Python 3 I correctly get 0.5, but on Python 2 I get 0
0.5
0
For Python2 / is integer division when the numerator and denominator are both int, you need to make sure to force floating point division
/
int
eg.
return (seq.count('G') + seq.count('C')) / float(len(seq))
alternatively, you can put
from __future__ import division
at the top of the file