not a big deal or anything, but, curiously:
Tim Peters
tim.peters at gmail.com
Wed Dec 13 01:31:07 EST 2006
[Simon Schuster]
> following this tutorial,
Which tutorial?
> I copied and pasted:
>
> from string import *
>
> cds = """atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaaa
> tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg
> ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc
> ccagcgttttggcgaattgcatattcaccctgtttacccgcatgccgaaggggttgacgagatca
> tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt
> attgaaacgccacccgcaggggcgattctggcagctaaagagttaccttcgaccggcggtgatac
> gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg
> ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcaaaaccgaggag
> gaacatcaacgctggcgcgaggcggtcgcgaaaaacccgccgttgctacatccggtggtgcgaac
> gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg
> tgagcgagaaagagagcgaagccttgttaagttttttgtttgcccatatcaccaaaccggagttt
> caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta
> tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttggggataaac
> cgttttatcgggcggggtaa""".replace("\n","")
>
> gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds)
>
> print gc
>
> -fin-
>
> which should yield: 0.54460093896713613..
>
> but when I ran it I got: 0.544600938967
>
> looking now I see it's truncating after a certain number of decimal
> places. any ideas why?
Read the Python Tutorial appendix on floating-point issues:
http://docs.python.org/tut/node16.html
As it says, str(a_float) rounds to 12 significant digits, and
repr(a_float) to 17. The `print` statement implicitly applies str()
to each item it prints.
More information about the Python-list
mailing list