Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The very basics of text files
with statement and exception handling
Summary
15. Question 2

Instruction

Good job! Now, Question 2.

Exercise

File question_2.txt contains some numbers. Count the number of positive numbers in the file, and print that value to the output.

Some lines may contain letters instead of digits. In such cases, simply ignore them and move on to subsequent lines.

Stuck? Here's a hint!

Use the int(line) function to convert a given file line (a string) to a number. Remember that int() throws a ValueError if it cannot convert the string to an integer.