def _read(prompt: str, typ=None):
    """Reads input and converts it to the respective type."""
    while True:
        raw = input(prompt)
        if typ is not None:
            try:
                return typ(raw)
            except (TypeError, ValueError):
                print(f'Invalid {typ}: {raw}.')
                continue
        return raw
