Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 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"
- # 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 :(")
- Provider=Microsoft.Jet.OLEDB.4.0
- Provider=Microsoft.ACE.OLEDB.12
- Public Sub OleInsert1()
- ' start with simple connection string and get a connection object instance
- Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "mathsquiz.accdb"
- Dim dbConn As Data.OleDb.OleDbConnection
- dbConn = New System.Data.OleDb.OleDbConnection(strConnectionString)
- ' now get a command and default its connection to the connection object above
- Dim dbCmd As Data.OleDb.OleDbCommand
- dbCmd = New System.Data.OleDb.OleDbCommand("", dbConn)
- ' prepare the sql-insert command. I have explicitly added "parm" for the VALUES
- ' to differentiate between the literal columns vs what you intend to pass in as parameters,
- ' otherwise sql will self-resolve as the column of the table. Here you are explicitly
- ' calling as a named parameter.
- dbCmd.CommandText = "insert into INSERT INTO question " &
- "(questiondescription, realanswer, answerA, answerB, answerC,answerD) " &
- " VALUES " &
- "( parmDescription, parmRealanswer, parmAnswerA, parmAnswerB, parmAnswerC, parmAnswerD)"
- ' now adding your parameters directly from the textboxes...
- ' but you should also be checking for NULL values,
- ' but this example is not a full working or error-trapping solution
- dbCmd.Parameters.AddWithValue("parmDescription", txtdescription.Text)
- dbCmd.Parameters.AddWithValue("parmRealAnswer", txtrealanswer.Text)
- dbCmd.Parameters.AddWithValue("parmAnswerA", txtanswera.Text)
- dbCmd.Parameters.AddWithValue("parmAnswerB", txtanswera.Text)
- dbCmd.Parameters.AddWithValue("parmAnswerC", txtanswera.Text)
- dbCmd.Parameters.AddWithValue("parmAnswerD", txtanswera.Text)
- ' Now, open the connection to the database. Just having the connection doesnt open it.
- If (dbConn.Open()) Then
- ' Finally execute it.
- dbCmd.ExecuteNonQuery()
- ' close connection when finished
- dbConn.Close()
- End If
- End Sub
Add Comment
Please, Sign In to add comment