This should be `except (TypeError, ValueError):` (the same goes for the original code, which is not tested for invalid arguments)