(Visual Studio 2015)
当用户输入数据时,我需要帮助将文件添加到python
def print_board(board):
print "The board look like this: \n"
for i in range(3):
print " ",
for j in range(3):
if board[i*3+j] == 1:
print 'X',
elif board[i*3+j] == 0:
print 'O',
elif board[i*3+j] != -1:
print board[i*3+j]-1,
else:
print ' ',
if j != 2:
print " | ",
print
if i != 2:
print "-----------------"
else:
print
def print_instruction(): 打印“请使用以下单元格号码进行移动” print_board([2,3,4,5,6,7,8,9,10])
def get_input(转):
valid = False
while not valid:
try:
user = raw_input("Where would you like to place " + turn + " (1-9)? ")
user = int(user)
if user >= 1 and user <= 9:
return user-1
else:
print "That is not a valid move! Please try again.\n"
print_instruction()
except Exception as e:
print user + " is not a valid move! Please try again.\n"
def check_win(board): win_cond =((1,2,3),(4,5,6),(7,8,9),(1,4,7),(2,5,8),(3,6,9) ,(1,5,9),(3,5,7)) 对于win_cond中的每一个: 尝试: 如果板[每个[0] -1] ==板[每个[1] -1]和板[每个[1] -1] ==板[每个[2] -1]: 返回板[每个[0] -1] 除了: 通过 返回-1
def quit_game(board,msg): print_board(板) 打印消息 退出()
def main():
# setup game
# alternate turns
# check if win or end
# quit and show the board
print_instruction()
board = []
for i in range(9):
board.append(-1)
win = False
move = 0
while not win:
# print board
print_board(board)
print "Turn number " + str(move+1)
if move % 2 == 0:
turn = 'X'
else:
turn = 'O'
# get user input
user = get_input(turn)
while board[user] != -1:
print "Invalid move! Cell already taken. Please try again.\n"
user = get_input(turn)
board[user] = 1 if turn == 'X' else 0
# advance move and check for end game
move += 1
if move > 4:
winner = check_win(board)
if winner != -1:
out = "The winner is "
out += "X" if winner == 1 else "O"
out += " :)"
quit_game(board,out)
elif move == 9:
quit_game(board,"No winner :(")
答案 0 :(得分:1)
您的访问数据库是mathsquiz.accdb
(不是mdb)。
替换提供者:
Provider=Microsoft.Jet.OLEDB.4.0
使用Microsoft ACE OLEDB 12.0提供程序:
Provider=Microsoft.ACE.OLEDB.12
安装驱动程序Microsoft ACE OLEDB 12.0