samedi 20 juin 2015

Python 3 How to check if a variable is in a list

I'm trying to make a TicTacToe game, and I do have a basically working prototype, managed to convert it to an exe file and so forth, but I'm going back and trying to create a condition that the input must be a valid option or else an error message is popped up and the p1 function restarted. How do I have python check if the input matches any one item on a list?

Ignore the globals, they haven't got anything to do with problem, they're for the board.

def p1():
    global top
    global a1
    global a2
    global a3
    global b1
    global b2
    global b3
    global c1
    global c2
    global c3
    print()
    print('Player One, it is your move')
    x = input()
        if str(x) == any('a1','A1','a2','A2','a3','A3','b1','B2','b3','B3','c1','C1','c2','C2','c3','C3'):
            # A lot of code goes here
    elif x == 'restart':
        begin()
    else:
        print('Invalid Command')
        print()
        p1()

Aucun commentaire:

Enregistrer un commentaire