sum_ = 0 numbers = 0 for line in lines: try: sum_ += int(line) numbers += 1 except ValueError: passI am assuming that list comprehension is not allowed so here is one way to do it. It's readable and clear.
I just have learned something new. Stripping whitespace characters is not necessary to convert a string to an integer. I tried it couple of minutes ago.
>>> int(' \t10 \n') 10