A search for the most likes that stops halfway

Code review · Medium · §13.6 [Pair coding with AI] Asking to add exception handling

You had a function that finds the largest value in a list of likes stored as text. You asked an AI, "Fix it so that no errors happen," and got this code. It runs without errors, but it prints 120. Fix it so that it reports and skips only the entries that are not numbers, like Skipped: private, and prints 300. Write the name of the error to catch after except, so that unexpected mistakes, like None mixed into the list, still show up as errors.

Code to fix

def best_likes(texts):
    best = 0
    try:
        for t in texts:
            n = int(t)
            if n > best:
                best = n
    except:
        pass
    return best

likes = ["120", "private", "300", "80"]
print(best_likes(likes))

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.