An error raised again inside except

Predict the output · Challenge · §13.4 Cleaning up and refusing honestly

This function tries to convert text to an integer, and if that fails, it tries once more through a float. Predict the output without running the code.

Code

def to_number(text):
    try:
        return int(text)
    except ValueError:
        print("Retrying as float:", text)
        return int(float(text))
    finally:
        print("Checked:", text)

print(to_number("3.7"))
print(to_number("lots"))
print("Done")

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.