Question: def validate _ symbol _ counts ( fleet _ grid: list [ list [ str ] ] , ship _ symbols: list [ str ]

def validate_symbol_counts(fleet_grid: list[list[str]],
ship_symbols: list[str],
ship_sizes: list[int])-> bool:
"" "Return True if and only if fleet_grid contains each ship symbol in
ship_symbols the correct corresponding number of times from ship_sizes,
and nothing else except for the EMPTY character.
ship_symbols and ship_sizes are parallel lists.
Note: This function does not consider whether ship symbols are positioned
in an appropriate manner to form a complete ship. It simply validates the
symbol counts.
Preconditions:
i=0def validatesymbolcounts(fleetgrid: list[list[str]],
shipsymbols: list[str],
shipsizes: list[int]) bool:
"""Return True if and only iffleetgrid contains each ship symbol in
shipsymbols the correct corresponding number of times from shipsizes,
and nothing else except for the EMPTY character.
shipsymbols and shipsizes are parallel lists.
Note: This function does not consider whether ship symbols are positioned
inan appropriate manner to form a complete ship. It simply validates the
symbol counts.
Preconditions:
-0 len(fleetgrid)
- len(fleetgrid[i])== len(fleetgrid)
for each value ofiin range(len(fleetgrid))
- len(shipsymbols)== len(shipsizes) and 0 len(shipsymbols)
- len(shipsymbols[i])==1
for each value ofiin range(len(shipsymbols))
-1 len(shipsizes[i])
for each value ofiin range(len(shipsizes))
>>> grid =[[EMPTY,'b', EMPTY],[EMPTY,'b', EMPTY],['a','a','a']]
>>> ships =['a','b']
>>> sizes =[3,2]
>>>validatesymbolcounts(grid, ships, sizes)
True
>>> grid =[['b', EMPTY, EMPTY],[EMPTY,'b','a'],['a','a', EMPTY]]
>>> ships =['a','b']
>>> sizes =[3,2]
>>>validatesymbolcounts(grid, ships, sizes)
True
>>> grid =[['d','a','n'],[EMPTY,'i','s'],['f','i','t']]
>>> ships =['a','d','f','i','n']
>>> sizes =[1,1,1,2,1]
>>>validatesymbolcounts(grid, ships, sizes)
False
"""
 def validate_symbol_counts(fleet_grid: list[list[str]], ship_symbols: list[str], ship_sizes: list[int])-> bool: "" "Return True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!