Exceptions – Solution [0]

Possible solution for the calculator:

def input_side():
    while True:
        raw_input = input("Enter the side of a square in centimeters: ")
        try:
            side = float(raw_input)
        except ValueError:
            print(f"{raw_input} is not a number!")
        else:
            if side < 0:
                print(f"{raw_input} is a negative number!")
            else:
                break
    return side

def get_square_perimeter(side):
    assert side >= 0
    return 4 * side

def get_square_area(side):
    assert side >= 0
    return side ** 2

def main():
    side = input_side()
    perimeter = get_square_perimeter(side)
    area = get_square_area(side)

    print(f"The perimeter of a square with a side of {side} cm is {perimeter} cm.")
    print(f"The area of a square with a side of {side} cm is {area} cm2.")

if __name__ == "__main__":
    main()