Yes, I think your code counts as using it. Your instructor probably doesn't want you to store all the numbers - luckily you don't have to.
Since this is an assessed exercise I won't write your code for you, but I'll explain the basic approach. You need to just keep two integers to do this - one number is the count of the numbers you've seen in the file so far, the other one is the largest number so far. For each number you read, you store the max()
of the largest so far and then number you've just seen, and you simply add one to the counter.
One gotcha - if you start the largest number at zero, then you'll get an incorrect result if all the numbers in the file are negative. You don't specify whether negative numbers are allowed, but it's potentially valid. To avoid this, initialise the value with None
to start with, and then just set it to the first number that you see in the file if the value is None
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…