I’m a beginner at programming and I want to build a warship game in python 3.6 for my school project, I have some mistakes but I don’t know how to fix it. If you try to run my code, run it until there is a mistake because sometimes there is no problem. I used to have pop out of range in placer_bateau_verticalement function and a list index out of range mistakes. Here is my code :

` """//----------------bibliothèques----------------\""" import random """//----------------initialisation des variables----------------\""" grid_playerA_init = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #IA's grid (player A) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] grid_playerB_init = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #Player's grid (player B) 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] previous_shots = []#empty matrix which will contain all the shots touch = False #False because we don't already touch a boat NbBoatTouchPlayer = 0 #count the amount of time the player touches a boat, it will help to know the end of the game NbBoatTouchIA = 0 #count the amount of time the IA touches a boat, it will help to know the end of the game """//----------------fonctions----------------\""" def replaceBoat():#replace the '0' by '1' to symbolise a boat grid_playerA_init.pop(position) grid_playerA_init.insert(position, 1) def can_place_boat_here(x,y, direc, length):# check if there is no collision between boats if direc == 0: # verticle direction for i in range(length): if (x + y*10+10*i) < 100:#if the boat doesn t exceed if grid_playerA_init [x +10*y + 10*i] == 1:#if there is already an other boat return False elif (x + y*10 +10*i) >= 100:#if we exceed the grid for j in range(length - i): #print((x + 10 * y) - (10 * i)) #print (i) #print("can_place_boat_here") #print(x,y,i) if grid_playerA_init[(x + 10 * y) - (10* i)] == 1: #if there is already a boat return False return True if direc == 1: # horizontal direction for i in range(length): if ((x + 10*y + i)-9) % 10 != 0: if grid_playerA_init [x + 10*y + i] == 1: return False elif ((x+10*y)-9) % 10 == 0: for j in range(length - i): if x+10*y-i == 1: return False return True return True def place_boat_vertically(x,y,direc,lenght):#place a boat vertically with the coordinates if can_place_boat_here(x,y, direc,lenght): for i in range(lenght): global position position = x + y*10 if position > 100: position = position- 10 * i for j in range(lenght-i): position = position - 10 #print("place_boat_vertically") #print(x,y) replaceBoat() x = x + 10 else: ##### while can_place_boat_here(x,y, direc,lenght) == False: print("FALSE VERTC") print(lenght) """ -------------------------------------TEST-------------------------------------""" x = random.randint(0, 9) y = random.randint(0, 9) print("x") print(x) print("y") print(y) for i in range(lenght): position = x + y*10 if position > 100: position = position- 10 * i for j in range(lenght-i): position = position - 10 #print("place_boat_vertically") #print(x,y) replaceBoat() x = x + 10 def place_boat_horizontally(x,y,direc,lenght):#place a boat horizontally with the coordinates if can_place_boat_here(x,y, direc,lenght): for i in range(lenght): global position position = x + y * 10 #print("place_boat_horizontally") #print(x,y) if (position - 9) % 10 == 0: replaceBoat() position = position -1 * i for j in range(lenght - i): position = position - 1 replaceBoat() else: replaceBoat() x = x + 1 else: ##### while can_place_boat_here(x,y, direc,lenght) == False: print("FALSE HORIZ") print(lenght) """ -------------------------------------TEST-------------------------------------""" x = random.randint(0, 9) y = random.randint(0, 9) print("x") print(x) print("y") print(y) for i in range(lenght): position = x + y * 10 #print("place_boat_horizontally") #print(x,y) if (position - 9) % 10 == 0: replaceBoat() position = position -1 * i for j in range(lenght - i): position = position - 1 replaceBoat() else: replaceBoat() x = x + 1 """ -------------------------------------END OF THE TEST-------------------------------------""" def check_shot(shot):#check if the shot has not already been fired for i in range(len(previous_shots)): if previous_shots[i] == shot: return False return True def replaceshot(shot):#replace the boat touched by an X del grid_playerB_init[shot] #delete the touched element grid_playerB_init.insert(shot, 'X') #by an X def IA (): shot = random.randint(0, 99) if check_shot(shot): previous_shots.append(shot) if grid_playerB_init[shot] == 1: replaceshot(shot) touch = True i = 1 nextshot = shot + i if grid_playerB_init[nextshot] == 1: # + 1 (right) replaceshot(nextshot) i = i + 1 nextshot = shot + i elif grid_playerB_init[nextshot] == 0: # - 1(left) i = 1 # variable reset nextshot = shot - 1 if grid_playerB_init[nextshot] == 1: replaceshot(nextshot) i = i + 1 nextshot = shot - i elif grid_playerB_init[nextshot] == 0: # + 10 (upstair) i = 1 # variable reset nextshot = shot - 10 if grid_playerB_init[nextshot] == 1: replaceshot(nextshot) i = i + 10 nextshot = shot - i elif grid_playerB_init[nextshot] == 0: # - 10 (downstair) i = 1 # variable reset nextshot = shot + 10 if grid_playerB_init[nextshot] == 1: replaceshot(nextshot) i = i + 10 nextshot = shot + i def IA_bad(): # just a simple IA which fires randomly with no logic shot = random.randint(0, 99) if check_shot(shot): previous_shots.append(shot) def Endgame(): #function which makes end of the game when all the boats are touched by one of the players if NbBoatTouchPlayer == 14 or NbBoatTouchIA == 14: #5+4+3+2 = 14 print("END OF THE GAME") print("your grid :") print(grid_playerB_init) print("IA's grid :") print(grid_playerA_init) """//----------------corps du programme----------------\""" for boat in range(2, 6): # we place the boats of 2;3;4 and 5 cases direction = random.randint(0, 1) # choose a random integer between 0 and 1. 0 stands for vertically and 1 stands for horizontally positionX = random.randint(0, 9) positionY = random.randint(0, 9) if direction == 0: place_boat_vertically(positionX, positionY, 0, boat) if direction == 1: place_boat_horizontally(positionX, positionY, 1, boat) print (grid_playerA_init) for loop in range(200): #IA's launch IA() print("") print(grid_playerB_init) print("") print(previous_shots) `