-1

I'm trying to get multiple inputs from users and break the loop by End of File(EOF) error.

while True:
try:
    n, l, c = map(int,input().split())

except EOFError:
    break

But when the user gives multiple inputs and then press Enter the ValuEroor warning has come.

ValueError: not enough values to unpack (expected 3, got 0)

In this scenario, Is there any way to get EOFEroor to break the loop and avoid ValueEoor?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 10 '21 at 00:08

1 Answers1

0

You will only get EOFError if the user presses CTRL-D. Just add ValueError to the caught exceptions:

except (EOFError, ValueError):

or, if needed to be handled differently:

except EOFError:
    ...
except ValueError:
    ...

You will need it anyway in case the user enters a string that can't be converted to int.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154