Trying to run battleship program in actual python program


from random import randint

board = []

for x in range(5):

def print_board(board):
    for row in board:
        print " ".join(row)

print "Let's play Battleship!"

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)

for turn in range(4):
    guess_row = int(raw_input("Guess Row:"))
    guess_col = int(raw_input("Guess Column:"))

    if guess_row == ship_row and guess_col == ship_col:
        print "Congratulations! You sunk my battleship!"
        if (guess_row <0 or guess_row >4) or (guess_col < 0 or guess_col >4):
            print "That's not even in the ocean!"
        elif(board[guess_row][guess_col] == "X":
             print "You've already guess that!"
             print "You missed my battleship!"
        if turn == 3:
             print "Game Over"
    print "Turn", turn +1

Not running and has multiple errors and will not run. Any help would be great


what are the errors? Which version of python are you using?


man do i learn in this site a specific version of python or what?


well yes, you run a specific python version.


what is this version?


it is 2.7.3, not sure about the last digit. But the last digit always has really small changes


is it the most used?


and do i have to learn another version of python to program on another versions?


python2 and python3 are not compatible. There is some difference in syntax (print with brackets) and more

If you write a new app, you should use python3. If you learn python2, there is just a small step to python3. Sometimes you have library's which only exist in python2, or you want your program to work for both 2 and 3.


okay thanks i got now i intend to learn both thanks i got a lot to do


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.