I’m looping through a file to find the highest value and then return the value and number of lines. If I didn’t convert myMax with int() I would get an unordered type error with the variable set as a string. What did I forget?!
def main():
myMax= 0
myCount = 0
myFile = open("numbers.dat", 'r')
for line in myFile :
myCount = myCount + 1
if int(line) > int(myMax):
myMax = line
myFile.close()
print ("Out of %s lines, the highest value found was %s" %(myCount, myMax))
main()
You need to change
myMax = linetomyMax = int(line). This will also makeif int(line) > int(myMax):convertable toif int(line) > myMax: