Question

python def flood_map(map, rise): Given a map and a non-negative amount of water rise as an...

python

def flood_map(map, rise): Given a map and a non-negative amount of water rise as an int, modify the given map (returning None), such that the sea level is that much higher. Each land spot is effectively lowered by rise to keep zero representing the (new) sea level; any land that goes underwater ends up as a zero to represent water, regardless of whether it was adjacent to water or not.

• Assume: map is a map as defined above, and rise is a non-negative int.

• Restriction: You must modify the original map in this function.  

flood_map([[10,10,4],[9,9,5],[8,8,6]],5)

5  5  0   

4  4  0

3  3  1  

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def flood_map(map, rise):
    for i in range(len(map)):
        for j in range(len(map[i])):
            map[i][j] -= rise
            if map[i][j] < 0:
                map[i][j] = 0


map = [[10, 10, 4], [9, 9, 5], [8, 8, 6]]
flood_map(map, 5)
print(map)

Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
python def flood_map(map, rise): Given a map and a non-negative amount of water rise as an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the...

    PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the map referred to is pictured in the screenshot. Need help with these 4 tasks: Function 4: def is_map(map) : given a map (see screenshot), does it meet the following criteria? 1) it is a list of lists of values of type int; 2) it has at least one row and one column; 3) it’s rectangular (all sub-lists are same length); 4) only non-negative ints...

  • please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each...

    please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT