2013-08-21 91 views
-3

出于某种原因,我的剧本是印刷的每一个值为零,即使列表包含非零数字:脚本打印所有零

#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]) 

我的输出低于:

 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 

为什么所有他们是0?

+0

你期望得到?你的投入是什么? – interjay

+2

请为您的问题选择更多描述性标题。我知道一些好的,简单的,但是'python an error'告诉我们什么都没有。 – thegrinner

+0

您使用整数除法并得到“0”。使用像这样的浮动部门:A1 = A [i] * 3/100.0 – akozin

回答

5

3/1000 in python(整数向下取整),请尝试3.0/100,而不是使用浮点数。

+1

只是为了明确,这只在Python 2.x中才是真实的。在Python 3.0中,'3/100'产生一个浮点数。 – SethMMorton

2

您可以转换您integersfloats或执行下列操作。因为第一个进口,

from __future__ import division