from typing import Optional


def elicit_float(prompt: str = "",
                 err: str = "Invalid input, try again",
                 default: Optional[float] = None) -> float:
    """Prompt the user for a float.

    Args:
        prompt (str, optional): String with which to prompt the user. Should
            not contain trailing space or colon, as these will be added.
            Defaults to "".
        err (str, optional): Message to show on invalid input.
            Defaults to "Invalid input, try again".
        default (Optional[float], optional): Default value to use if the user
            enters nothing. If None, the user must enter a float.
            Defaults to None.

    Returns:
        float: A float, as entered by the user, or, if given, default.
    """
    if default is not None:
        prompt += f'(default {default})'
    prompt += ": "
    while True:
        try:
            i = input(prompt).strip()
            if i == "" and default is not None:
                return default
            n = float(i)
            return n
        except ValueError:
            print(err)