sq_coords = [(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)] squares = [("top",1),("left",1),("middle",2),("bottom",3),("right",3)] win_cond = [((1,1),(2,1),(3,1)),((1,2),(2,2),(3,2))] complete = False print "I will go first" print "I have gone in the top left corner" pfilled = [] cfilled = [(1,1)] def trans_move(move): move = move.split() for i in squares: if move[0] == i[0]: mv_coord = [i[1]] if move[1] == i[0]: mv_coord.append(i[1]) return mv_coord def check(mv_coord): if (mv_coord[0],mv_coord[1]) in filled: checked = False else: checked = True return checked while complete == False: move = raw_input("Enter row, then column of the square you want to fill:\n") mv_coord = trans_move(move) if check(mv_coord): pfilled.append((mv_coord[0],mv_coord[1])) mvd = True else: print "Invalid Move" mvd = False print mv_coord, filled break
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question