-1

[The game will be displayed as nine blocks, with rows and columns marked numerically, of which the squares' coordinates will be a combination; ex: 11(first column, first row), 12(first column, second row), 13, 21, 22, etc. till 33] I have the display down, just can't figure out this one issue.

The following is my code for accepting moves:

askformovestr = "Turn: X. Please enter the coordinates for the square in which you wish to drop your piece, with column number followed by row number(e.g. 11 drops to top left square, 12 to the square below it, 23 to the square in the third row, second column, etc., etc.): "
def askformove():
    inmove = int(input(askformovestr))
    while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:
        print("Invalid input, sorry. Please try again.")
        inmove = int((input("Turn: X. Please enter the coordinates for the square in which you wish to drop your piece(e.g. 1B, 2C, 3A, etc.): ")))
askformove()
zvl
  • 1
  • 2

1 Answers1

0

Maybe instead this:

while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:

Try this:

while (inmove != 11 or inmove != 12 or inmove != 13 or inmove != 21 or inmove != 22 or
       inmove != 23 or inmove != 31 or inmove != 32 or inmove != 33):
martineau
  • 119,623
  • 25
  • 170
  • 301
Sigma
  • 16
  • 4
  • Didn't work at first, but then I changed all "or"s to "and"s and that worked(which it wasn't with my method), so thank you! – zvl Feb 13 '22 at 15:49
  • no problem, i guess – Sigma Feb 13 '22 at 15:51
  • you can also use: while inmove is not 11 and inmove is not 12 and inmove is not 13 and inmove is not 21 and inmove is not 22 and inmove is not 23 and inmove is not 31 and inmove is not 32 and inmove is not 33: – jimmy Feb 13 '22 at 16:00
  • it's much more efficient use `while inmove not in [11,12,13,21,22,23,31,32,33]:` – Deera Wijesundara Feb 13 '22 at 16:08
  • 1
    @jimmy In Python `!=` is defined as not equal to operator. It returns `True` if operands on either side are not equal to each other, and returns `False` if they are equal. Whereas `is not` operator checks whether id() of two objects is same or not. So even if the answer is correct. `!=` is much faster than 'is not' when checking equality. – Deera Wijesundara Feb 13 '22 at 16:14