Search code examples
pythonpython-3.xinput

Assigning multiple values from a single input statement disregarding whitespace


I'm making a Connect Four game where the board size can be decided by the players while ignoring the amount of spaces between the numbers.

inp = input("Please input the size of the board youd like with the number of rows before "
            "the number of columns. If you would like to quit, please type quit").split()
while inp != "quit":
    nRows, nCols = inp

This method has worked for me previously, but it keeps causing an error:

ValueError: not enough values to unpack


Solution

  • You are getting error because you're passing only one value as input. Instead, you should pass input like

    1 2

    input("msg").split() split by default takes space as separator

    So your code is correct but you're providing wrong input