I'm trying to write a program that will determine the total number of lines, columns, digits, as well as the maximum and minimum number. However it returns the wrong data and can't count any negative numbers. My program is...
And the files that I'm trying to use are
Month Minimum Maximum Average
Jan -16 -7 -11.5
Feb -15 -5 -10
Mar -8 1 -4
Apr 0 11 6
May 7 19 13
Jun 12 24 18
Jul 14 27 21
Aug 14 26 20
Sep 9 20 15
Oct 3 14 9
Nov -2 5 2
Dec -12 -4 -8
and
Country Gold Silver Bronze Total
US 9 15 13 37
GE 10 13 7 30
CA 14 7 5 26
NO 9 8 6 23
AU 4 6 6 16
RF 3 5 7 15
KO 6 6 2 14
CH 5 2 4 11
SW 5 2 4 11
FR 2 3 6 11
Anyone who can help me out??
Code:
max = 0 min = 0 def getMaxMin(digitsList): global max max = digitsList[0] global min min = digitsList[0] for digit in digitsList: if digit > max: max = digit if digit < min: min = digit import sys def main(): filename = sys.argv[1] file = open(filename,"r") line = file.readline() lines = 0 columns = 0 digits = 0 digitsList = [] while line != "": line = line.strip('\n') lines += 1 words = line.split('\t') for word in words: if word.isdigit(): digits += 1 digitsList.append(int(word)) columns = len(words) line = file.readline() getMaxMin(digitsList) print "lines = ",lines print "columns = ",columns print "digits = ",digits print "max = ",max print "min = ",min main()
And the files that I'm trying to use are
Month Minimum Maximum Average
Jan -16 -7 -11.5
Feb -15 -5 -10
Mar -8 1 -4
Apr 0 11 6
May 7 19 13
Jun 12 24 18
Jul 14 27 21
Aug 14 26 20
Sep 9 20 15
Oct 3 14 9
Nov -2 5 2
Dec -12 -4 -8
and
Country Gold Silver Bronze Total
US 9 15 13 37
GE 10 13 7 30
CA 14 7 5 26
NO 9 8 6 23
AU 4 6 6 16
RF 3 5 7 15
KO 6 6 2 14
CH 5 2 4 11
SW 5 2 4 11
FR 2 3 6 11
Anyone who can help me out??
Comment