This Programming Assignment is similar to P6.35 in your text and you must refer to that problem for the general idea of what this problem does. The Python representation of the matrix must be a list of lists. It differs from P6.35 in the following ways:
- It is not restricted to 1010 matrices. It should work for any size from 55 and larger.
- The matrix will be read from a file (see chapter 7) named terrain.txt. This file will have a row of integers representing elevations on each line. The integers will be separated by spaces. For ease of formatting the output you can assume that all elevations are less than 1000.
- A second file named flood.txt will contain one integer per line. These represent flood levels and your program should produce a map (same size as read from terrain.txt) to show the flooded terrain for each integer in the file.
- Your solution must include at least the following functions:
o readTerrain() open and read terrain.txt, close the file, return the matrix (a list of lists) o printTerrain(elevMatrix) print a map of terrain elevations (from readTerrain() )
o calcFlood(elevMatrix, h2oElevation) return a matrix of strings (each position a * or a for
flooded and not flooded respectively) Any location whose elevation is less than or equal to the
h2oElevation is considered flooded.
o printFlood(floodMatrix) cleanly print the matrix as returned by calcFlood
- Sometimes input presented to a program contains bad data. Any elevation value that is not an integer should be printed as – with printing the flood map. This program will be easy to implement if you leave the data as strings in elevMatrix and use try-except (see chapter 8) when converting to integers for comparing to the flood level.
- Do NOT use list comprehensions or the .format string method.
A sample output is shown below. Build your own files to test your code.
100 | 104 | 107 | 103 |
102 | 101 | 105 | 100 |
103 | 99 | 102 | 96 |
97 | 94 | 98 | 100 |
94 | 93 | 95 | 98 |
xx | yy | zz | 101 |
99 | 101 | 104 | 107 |
109 106 112 115106 xxx yyy zzz101 105 110 122104 100 109 113100 103 108 110104 108 110 115
110 110 115 125
Flooding at elevation = 95
Tables to left printed by printFlood using data Provided by calcFlood
Flooding at elevation = 100
*
*
* *
* * * * *
* * * * *
*
Flooding at elevation = 105
* * *
* * * *
* * * * * * * * * * * * * * * * * * * *
* * *
Reviews
There are no reviews yet.