When the settings file is missing and when it is broken

Write code · Medium · §13.5 The math helper gets sturdy

Complete the function read_limit(filename), which reads a settings file that holds the number of notifications to receive per day and returns that number as an integer. A value of 0 means notifications are turned off. If the file does not exist, treat it as the first run and return the default value 20. If the file's contents are not an integer, do not hide it; let the program stop with a ValueError. Do not catch any error other than a missing file.

Starter code

def read_limit(filename):
    # Write your code here
    pass

print("Notification limit:", read_limit("limit.txt"))

File limit.txt

50

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.