Extra credit


Well I have few issues with this, it feels like a real deep water for me.

from random import randint
import datetime
import time

now = datetime.datetime.now()

print ("\r\nBonsoir, Sailor! \r\n")
print ("Welcome to the Battleships, official vodka game, okurwa games presents.")
print ("It is already " + unicode(now.replace(microsecond=0)) + " - Perfect time to drink! \r\n")

board = []

for x in range(9):
    board.append(["O"] * 9)

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

print "Let's play Battleships! \r\n"

def random_row(board):
    return randint(0, len(board) - 3)

def random_col(board):
    return randint(0, len(board[0]) - 3)

ship_row = random_row(board)
ship_col = random_col(board)
print ship_row
print ship_col

# Everything from here on should go in your for loop!
# Be sure to indent four spaces!

for turn in range(0,9):
    print "Turn", turn + 1
    guess_row = int(raw_input("Guess Row:"))
    guess_col = int(raw_input("Guess Col:"))
    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 "Oops, that's not even in the ocean."
    elif(board[guess_row][guess_col] == "X"):
        print "You guessed that one already."
        print "You missed my battleship!"
        board[guess_row][guess_col] = "X"
    if turn == 3:
        print "Game Over"

First thing is that I wanted to start this app nicely but it gives error on codecademy, but on my pc works fine.

File "python", line 8
print ("
SyntaxError: EOL while scanning string literal

It has completed the excercise anyway somehow, do I even have to run this code on the website or can I have it on my own pc only?

Second thing is I have no idea yet how to do battleships of different sizes and how to do them multiple!
Looks like the randint part is responsible for that, but it feels vogue, I dont even know why it is "(0, len(board) - 3)"
or "(0, len(board[0]) - 3)... Maybe I did missed something earlier.

Rematches and other things seems easy, but Im stuck on these things above could use some hint..



remove \r in your print statement


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