Extra credit help?


#1

Ok so I think i might just be missing something obvious with this statement because it keeps saying invalid syntax on this one line.

def random_row(board):

i dont understand why. Am i missing something?


#2

It sounds like there could be an error in your code before you've written that line (such as missing indentation, parentheses, colons, etc), which means it's expecting something else.

Can you paste the code before (and including) that line?


#3

Well here is all of my code i have so far i am no were near done i just wanted to go back and check what i already had and there error for that came up. so its still really a work in progress.

# Battleship for two
from random import randint

board1 = []
board2 = []
boards = [board1, board2]
next_player = 1

for x in range(10):
    board1.append(["O"] * 10)
    board2.append(["O"] * 10)

def print_board(boards):
    board1 = boards[0]
    board2 = boards[1]

    if players[next_player] == player1:
        for row in board1:
            print (player1)
            print ("".join(row))
            
    elif players[next_player] == player2:
        for row in board2:
            print (player2)
            print ("".join(row))
            
    else:
            print (player1)
            print ("".join(row))
            
            print (player2)
            print ("".join(row))
            
print "Lets play battleship!"
print_board(boards)

print "READY PLAYER ONE ?"
ready = int(raw_input("Type Start To Begin:")

def random_row(board):
    return randint(0, len(board) - 1)
    
def random_col(board):
    return randint(0, len(board) - 1)
    
ship_row = random_row(board)
ship_col = random_col(board)

def guess_ship(playa):
    guess_row = int(input("Please guess a row number:"))
    guess_col = int(input("Also guess a column number: "))
    
print (print_board(board))

if guess_row == ship_row and guess_col == ship_col
    print "congratulations! You sunk the battleship!"
    
else:
    if ((guess_row > 10) or (guess_row < 0)) and ((guess_col > 10) or (guess_col < 0)):
        print "Oops your guess is out of bounds"
    if player1:
        elif (board[guess_row][guess_col] == "X")
            print "You already guessed that one"
    elif player2:
        elif (board[guess_row][guess_col] == "X")
            print "You already guessed that one"
    else:
        print "You missed the battleship"
        board[guess_row][guess_col] = "X"
        
turn = 1

max_games = int(input("Enter the maximum amount of games you want to play:"))        

player1 = str(raw_input("Enter the name of the first player:"))
player2 = str(raw_input("Enter the name of the second player:"))

player = [player1][player2]
player = 0

for turns in range(max_games):
turns = turn + 1
print ("Turn", turn)

next_player = (player % 2)
player = next_player + 1

    guess_ship(players[next_player])
    
    if turn == max_games:
        print "Game Over"
print(print_board(board))

#4

ready = int(raw_input("Type Start To Begin:")

There's your culprit line. Seems you're missing a closing parenthesis :wink:

If you get an invalid syntax error on something you're sure is correct, it's very likely to be a missing symbol/character. Your best bet in these situations is to work backwards from that line and see where the problem is (which is usually just the line before it).


#5

Thank you so much!!! Its so easy to over look the little things! Thank you!