为了保持一个干净的问题,问题在代码中被注释了:)
theOpenFile = open('text.txt', 'r')
highest = 0
for myCurrentString in theOpenFile.readlines():
## Simple string manipulation
stringArray = myCurrentString.split() ## to get value, this seems to
series = stringArray[0].split('.')[0] ## work perfectly when I
## "print series" at the end
if series > highest: ## This doesn't work properly,
highest = series ## although no syntantic or
print "Highest = " + series ## runtimes errors, just wrong output
print series
theOpenFile.close()
输出
Highest = 8
8
Highest = 6
6
Highest = 6
6
Highest = 8
8
Highest = 8
8
Highest = 7
7
Highest = 4
4