else and finally

Lab Python Intermediate 20 points

Read a number. In a try convert it to float. In except print bad input; in else print its square root (2 decimals, negative numbers give negative); in finally print done.

Input

One line.

Output

Two lines.

Example

Input

16

Output

4.00
done
Sample input available Sample output available
Editor
Python

Hints

else runs only if no exception happened.

finally always runs.

Solution explanation

Keep the try block small; put follow-up work in else and cleanup in finally.

Show solution
import math

text = input()
try:
    x = float(text)
except ValueError:
    print("bad input")
else:
    print(f"{math.sqrt(x):.2f}" if x >= 0 else "negative")
finally:
    print("done")
Output
Answer
HOME LEARN COMMUNITY DASHBOARD