Guest User

Untitled

a guest
Mar 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. print "The board look like this: n"
  2.  
  3. for i in range(3):
  4. print " ",
  5. for j in range(3):
  6. if board[i*3+j] == 1:
  7. print 'X',
  8. elif board[i*3+j] == 0:
  9. print 'O',
  10. elif board[i*3+j] != -1:
  11. print board[i*3+j]-1,
  12. else:
  13. print ' ',
  14.  
  15. if j != 2:
  16. print " | ",
  17. print
  18.  
  19. if i != 2:
  20. print "-----------------"
  21. else:
  22. print
  23.  
  24. valid = False
  25. while not valid:
  26. try:
  27. user = raw_input("Where would you like to place " + turn + " (1-9)? ")
  28. user = int(user)
  29. if user >= 1 and user <= 9:
  30. return user-1
  31. else:
  32. print "That is not a valid move! Please try again.n"
  33. print_instruction()
  34. except Exception as e:
  35. print user + " is not a valid move! Please try again.n"
  36.  
  37. # setup game
  38. # alternate turns
  39. # check if win or end
  40. # quit and show the board
  41.  
  42. print_instruction()
  43.  
  44. board = []
  45. for i in range(9):
  46. board.append(-1)
  47.  
  48. win = False
  49. move = 0
  50. while not win:
  51.  
  52. # print board
  53. print_board(board)
  54. print "Turn number " + str(move+1)
  55. if move % 2 == 0:
  56. turn = 'X'
  57. else:
  58. turn = 'O'
  59.  
  60. # get user input
  61. user = get_input(turn)
  62. while board[user] != -1:
  63. print "Invalid move! Cell already taken. Please try again.n"
  64. user = get_input(turn)
  65. board[user] = 1 if turn == 'X' else 0
  66.  
  67. # advance move and check for end game
  68. move += 1
  69. if move > 4:
  70. winner = check_win(board)
  71. if winner != -1:
  72. out = "The winner is "
  73. out += "X" if winner == 1 else "O"
  74. out += " :)"
  75. quit_game(board,out)
  76. elif move == 9:
  77. quit_game(board,"No winner :(")
  78.  
  79. Provider=Microsoft.Jet.OLEDB.4.0
  80.  
  81. Provider=Microsoft.ACE.OLEDB.12
  82.  
  83. Public Sub OleInsert1()
  84. ' start with simple connection string and get a connection object instance
  85. Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "mathsquiz.accdb"
  86. Dim dbConn As Data.OleDb.OleDbConnection
  87. dbConn = New System.Data.OleDb.OleDbConnection(strConnectionString)
  88.  
  89. ' now get a command and default its connection to the connection object above
  90. Dim dbCmd As Data.OleDb.OleDbCommand
  91. dbCmd = New System.Data.OleDb.OleDbCommand("", dbConn)
  92.  
  93. ' prepare the sql-insert command. I have explicitly added "parm" for the VALUES
  94. ' to differentiate between the literal columns vs what you intend to pass in as parameters,
  95. ' otherwise sql will self-resolve as the column of the table. Here you are explicitly
  96. ' calling as a named parameter.
  97. dbCmd.CommandText = "insert into INSERT INTO question " &
  98. "(questiondescription, realanswer, answerA, answerB, answerC,answerD) " &
  99. " VALUES " &
  100. "( parmDescription, parmRealanswer, parmAnswerA, parmAnswerB, parmAnswerC, parmAnswerD)"
  101. ' now adding your parameters directly from the textboxes...
  102. ' but you should also be checking for NULL values,
  103. ' but this example is not a full working or error-trapping solution
  104. dbCmd.Parameters.AddWithValue("parmDescription", txtdescription.Text)
  105. dbCmd.Parameters.AddWithValue("parmRealAnswer", txtrealanswer.Text)
  106. dbCmd.Parameters.AddWithValue("parmAnswerA", txtanswera.Text)
  107. dbCmd.Parameters.AddWithValue("parmAnswerB", txtanswera.Text)
  108. dbCmd.Parameters.AddWithValue("parmAnswerC", txtanswera.Text)
  109. dbCmd.Parameters.AddWithValue("parmAnswerD", txtanswera.Text)
  110.  
  111. ' Now, open the connection to the database. Just having the connection doesnt open it.
  112. If (dbConn.Open()) Then
  113. ' Finally execute it.
  114. dbCmd.ExecuteNonQuery()
  115. ' close connection when finished
  116. dbConn.Close()
  117. End If
  118. End Sub
Add Comment
Please, Sign In to add comment