The wrong error name

Code review · Basic · §13.3 What to catch

This code prints the name at each requested rank in a ranking list and reports a rank that does not exist, like Rank 5: not found. When you run it, it stops with an error. Fix one line so that it runs to the end. Write the exact name of the error to catch so that other errors are not swallowed too.

Code to fix

ranking = ["mina", "sora", "jun"]
ranks = [1, 3, 5]
for rank in ranks:
    try:
        print(f"Rank {rank}: {ranking[rank - 1]}")
    except KeyError:
        print(f"Rank {rank}: not found")

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.