-3

For some reason, my script is printing every value as zero even though the lists contain non-zero numbers:

#this is the specific part of my script, A, T, G % C are 4 lists that consists from 10 indexes, each of which is a different number

 for i in range(min(len(A), len(G), len(C), len(T))):
    A1=A[i]*3/100
    C1=C[i]*3/100
    G1=G[i]*3/100
    T1=T[i]*3/100

    tA.append(A1)
    tC.append(C1)
    tG.append(G1)
    tT.append(T1)

    i=i+1

print "       A        C        T        G"
print "143   %d       %d       %d       %d" %(tA[0],tC[0],tT[0],tG[0])
print "144   %d       %d       %d       %d" %(tA[1],tC[1],tT[1],tG[1])
print "145   %d       %d       %d       %d" %(tA[2],tC[2],tT[2],tG[2])
print "146   %d       %d       %d       %d" %(tA[3],tC[3],tT[3],tG[3])
print "147   %d       %d       %d       %d" %(tA[4],tC[4],tT[4],tG[4])
print "148   %d       %d       %d       %d" %(tA[5],tC[5],tT[5],tG[5])
print "149   %d       %d       %d       %d" %(tA[6],tC[6],tT[6],tG[6])
print "150   %d       %d       %d       %d" %(tA[7],tC[7],tT[7],tG[7])
print "151   %d       %d       %d       %d" %(tA[8],tC[8],tT[8],tG[8])
print "152   %d       %d       %d       %d" %(tA[9],tC[9],tT[9],tG[9])
print "153   %d       %d       %d       %d" %(tA[10],tC[10],tT[10],tG[10])

My output is below:

       A        C        T        G
143   0       0       0       0
144   0       0       0       0
145   0       0       0       0
146   0       0       0       0
147   0       0       0       0
148   0       0       0       0
149   0       0       0       0
150   0       0       0       0
151   0       0       0       0
152   0       0       0       0
153   0       0       0       0

Why all of them are 0?

thegrinner
  • 11,546
  • 5
  • 41
  • 64
  • What do you expect to get? What are your inputs? – interjay Aug 21 '13 at 13:16
  • 2
    Please choose more descriptive titles for your question. I know some of the good, simple ones are taken, but `python an error` tells us nothing. – thegrinner Aug 21 '13 at 13:17
  • You use integer division and got "0". Use float division like this: A1=A[i]*3/100.0 – akozin Aug 21 '13 at 13:18
  • 1
    @AshwiniChaudhary The issue with saying that question duplicates this question is that it assumes prior knowledge that the issue is with division and not, say, printing. – wheaties Aug 21 '13 at 13:24
  • 2
    @user2703153 when there is an error, you should try to find out yourself where exactly the problem is, e.g. by inserting print statements such as `print A1` to check whether the value is what you expect. By doing this you can localize the error and you will ultimately save time. Here, for example, you could eventually have found that `5*3/100` equals `0` and then asked us why that is. :) – flornquake Aug 21 '13 at 13:35

2 Answers2

5

3/100 is 0 in python (integers are rounded down), try 3.0/100 instead which will use floating point numbers.

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93
2

You can either convert your integers to floats or do the following as the very first import,

from __future__ import division