- 論壇徽章:
- 0
|
本帖最后由 hothat007 于 2014-01-23 13:39 編輯
DYC-P072-2 2014-01-21 12.zip
(18.85 KB, 下載次數(shù): 24)
2014-01-23 13:39 上傳
點(diǎn)擊文件名下載附件
新手學(xué)習(xí)Python不久,在編寫(xiě)查找文本中的最大值,但是代碼出現(xiàn)問(wèn)題,請(qǐng)大家指導(dǎo)謝謝- #coding:utf-8
- import os
- filename = 'DYC-P072-2 2014-01-21 12.txt'
- fr = 28
- to = 29
- filepath = os.getcwd()
- fileaddress = filepath + '\\' + filename
- f = open(fileaddress)
- i = 1
- count = 0
- buf = ''
- num = 0
- for lines in f.readlines():
- count = count + 1
- line = lines.split()
- if (float(line[0]) >= fr) and (float(line[0]) <= to):
- if i == 1:
- buf = line
- i = 0
- elif line[1] > buf[1]:
- buf = line
- num = count
- print line[1]
- print buf
- os.system('pause')
-
- print buf
- print num
- f.close()
- os.system('pause')
復(fù)制代碼
caonima.jpg (49.3 KB, 下載次數(shù): 91)
下載附件
2014-01-23 12:27 上傳
如圖我先查找到153這行數(shù)
可是我的代碼運(yùn)行結(jié)果卻是這樣的:
caonima2.jpg (5.33 KB, 下載次數(shù): 94)
下載附件
2014-01-23 12:28 上傳
|
|