我的部分代码
list1 = getCol('/home/milenko/EDIs/site1/newst2.txt')[1]
list2 = getCol('/home/milenko/EDIs/site1/newst2.txt')[2]
list3 = getCol('/home/milenko/EDIs/site1/newst2.txt')[3]
list4 = getCol('/home/milenko/EDIs/site1/newst2.txt')[4]
mm1 = [line.strip() for line in open("m1.dat", 'r')]
print mm1
ii1 = [int(x) for x in mm1]
print ii1
s1= 1
dt1= 1
dt2= 2
dt3= 5
dt4= 6
er1=0.022
for item in ii1:
if (item % 4 == 0)
print s1,item,list1[item-1],dt1,er1
Out put应该是这样的
1 5 1 2.364 0.022
1 5 2 30.364 0.022
1 5 5 2.351 0.022
1 5 6 44.606 0.022
1 6 1 2.372 0.022
1 6 2 33.290 0.022
1 6 5 2.290 0.022
1 6 6 43.799 0.022
1 7 1 2.414 0.022
1 7 2 37.071 0.022
1 7 5 2.281 0.022
1 7 6 44.331 0.022
if语句应该如何?
答案 0 :(得分:1)
这个documentation可能会帮助您了解Python中的条件语句。
例如:(因为SO鼓励提供一个例子)
>>> x = int(raw_input("Please enter an integer: "))
Please enter an integer: 42
>>> if x < 0:
... x = 0
... print 'Negative changed to zero'
... elif x == 0:
... print 'Zero'
... elif x == 1:
... print 'Single'
... else:
... print 'More'
...
More
在您的代码中,它应该是:
for item in ii1:
if (item % 4 == 0):
print s1,item,list1[item-1],dt1,er1
另一个参考文献是Learning Python the hard way。