title: Battleship Game.. a few issues with database and storing players Data
body: <p>I am trying to create a game of battleship in python that has the following:</p>
  
  <ul>
  <li>an SQLite database</li>
  <li>a user login and password, games won and highscore stored in the db</li>
  <li>display games won and highscore on login </li>
  </ul>
  
  <p>So far I am having issues with storing the data in the database if anyone has any help or guidance on what direction I should go next I would greatly appreciate it! </p>
  
  <pre><code>from random import randint
  import getpass
  import sqlite3
  
  #creating the database using SQLite
  def createTable():
      db = sqlite3.connect(':memory:')
      db = sqlite3.connect('MyBSdb') #this folder was created
      cursor = db.cursor()
      cursor.execute('''CREATE TABLE IF NOT EXISTS BSTable(name TEXT, password TEXT, wins INT, highscore INT)''')
      db.commit()
      db.close()
  
  def save(name,password):
      db = sqlite3.connect(':memory:')
      db = sqlite3.connect('MyBSdb')
      cursor = db.cursor()
      cursor.execute('''INSERT INTO BSTable(name,password,wins,highscore) values(?,?)''', (name,password,wins,highscore))
      db.commit()
      db.close()
  
  def get():
      db = sqlite3.connect(':memory:')
      db = sqlite3.connect('MyBSdb')
      cursor = db.cursor()
      cursor.execute('''SELECT name,password,wins,highscore from myTable''')
      results = cursor.fetchall()
      for result in results:
          print (result)
  
  
  if __name__  == '__main__':
      createTable()
      save('users','passw')
      get()
  
  def writeFile():
      #create file handle, open file for append
      file = open('Battleship.txt', 'a')
      text = 'Bob,hello'
      #write string s to file
      file.write(text + '\n')
      #close file handle after write operation
      file.close()
  
  def readFile():
      #create file handle, open file for append
      file = open('Battleship.txt', 'r')
      text = file.readlines()
      for line in text:
          print(line.split(",")[0])
          print(line.split(",")[1])
      #close file handle after write operation
      file.close()
  
  if __name__  == '__main__':
      writeFile()
      readFile()
  
  #creating a login and password
  users = {}
  status = ""
  
  def displayMenu():
      status = input("Are you registered user? y/n? ")
      if status == "y":
          oldUser()
      elif status == "n":
          newUser()
  
  def newUser():
      createLogin = input("Create login name: ")
  
      if createLogin in users:
          print("\nLogin name already exist!\n")
      else:
           createPassw = input("Create password: ")
              users[createLogin] = createPassw
          print("\nUser created\n")
  
  def oldUser():
      login = input("Enter login name: ")
      passw = input("Enter password: ")
  
      if login in users and users[login] == passw:
          print("\nLogin successful!\n")
      else:
          print("\nUser doesn't exist or wrong password!\n")
  
  while status != "q":
     displayMenu() #cant stop the loop here or figure out why it wont move on
  
  #building the gameboard
  board = []
  
  for x in range(5):
      board.append(["-"] * 5)
  
  def print_board(board):
      print(" ", " ".join("12345"))
      for letter, row in zip("ABCDE", board):
          print(letter, " ".join(row))
  
  #beginning the game
  print("Let's play Battleship!")
  print("Find and sink the ship!")
  print_board(board)
  
  score = 0 #using this to keep a score to store in the database
  win = True
  
  def wins():
      if win == True:
         win = score + 1 
  
  def random_row(board): 
      return randint(0, len(board) - 1)
  def random_col(board):
      return randint(0, len(board[0]) - 1)
  
  ship_row = random_row(board)
  ship_col = random_col(board)
  
  #the numbers and letters in this section are not aligning with the grid I created
  for turn in range(9):
      print ("Turn"), turn
      guess_row = int(input("Guess Row:"))
      guess_col = int(
          input("Guess Col:"))
  
      if guess_row == ship_row and guess_col == ship_col:
          win == True
          print("Congratulations! You sunk my battleship!")
          print("Your score is " + score ) #keeping score but how to save in db?
          break
      else:
          if (guess_row &lt; 0 or guess_row &gt; 5) or (guess_col &lt; 0 or guess_col &gt; 5):
              print("Oops, that's not even in the ocean.")
          elif(board[guess_row][guess_col] == "X"):
              print("You guessed that one already.")
          else:
              print("You missed my battleship!")
              board[guess_row][guess_col] = "X"
      if turn == 8:
          print("Game Over")
          print("Your final score is " + score ) 
      turn =+ 1
      print_board(board)
      #how to display games won and high score when user logs in? 
  </code></pre>