#๐Ÿ”’ Trying to figure out has ship function

11 messages ยท Page 1 of 1 (latest)

static questBOT
#

@stiff flicker

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stiff flicker
#
def has_ship(fleet_grid: list[list[str]], row_start: int, col_start: int,
             ship_symbol: str, ship_size: int) -> bool:
    """Return True if and only if a ship that (1) uses ship_symbol as its ship
    symbol and (2) has length ship_size appears in fleet_grid starting at
    position (row_start, col_start), where (row_start, col_start) is the
    top-most/left-most corner of the ship.

    If the ship has ship_size 2 or more and appears as both a column and a row,
    return False.

    Preconditions:
        - 0 < len(fleet_grid)
        - len(fleet_grid[i]) == len(fleet_grid)
              for each value of i in range(len(fleet_grid))
        - 0 <= row_start < len(fleet_grid)
        - 0 <= col_start < len(fleet_grid)
        - MIN_SHIP_SIZE <= ship_size <= MAX_SHIP_SIZE
        - fleet_grid[i][j] != ship_symbol for each of the coordinates
             (i, j) == (row_start - 1, col_start) or
             (i, j) == (row_start, col_start - 1)
             when those coordinates are valid indexes for fleet_grid
 
    >>> grid = [[EMPTY, 'b', EMPTY], ['a', 'b', EMPTY], [EMPTY, EMPTY, EMPTY]]
    >>> has_ship(grid, 0, 1, 'b', 2)
    True
    >>> has_ship(grid, 0, 1, 'b', 1)
    False
    >>> has_ship(grid, 0, 1, 'b', 3)
    False
    >>> has_ship(grid, 1, 0, 'a', 1)
    True
    >>> grid = [['b', 'b', 'b'], ['b', EMPTY, EMPTY], ['b', EMPTY, EMPTY]]
    >>> has_ship(grid, 0, 0, 'b', 3)
    False
    """```
#

I have some other functions

#

but I don't think they'll be useful

stiff flicker
#

are there any ideas

stiff flicker
#

.close

#

close

#

-close

#

/close

#

!close

static questBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.