Question: Write a PYTHON function plot_points that expects a dictionary as described in the Lab Exercise from Week 4 and returns nothing. It should print to
Write a PYTHON function plot_points that expects a dictionary as described in the Lab Exercise from Week 4 and returns nothing. It should print to the screen a "graph" of the points in the dictionary.
For example, if the dictionary is as follows:
my_points = { 'a':(4, 3), 'b':(1, 2), 'c':(5, 1) }
The resulting output to the screen should "plot" the letters a, b, and c at their coordinates like this:
3 . . . . a .
2 . b . . . .
1 . . . . . c
0 . . . . . .
0 1 2 3 4 5
This may involve writing a few auxiliary functions. Here's how I recommend doing it (not required!):
* First you can use the max_coordinate_value function written during the Lab Exercise in Week 4 to get the maximum values for the X and Y coordinates found among all the points. Alternately, you may use the max_coordinate_value function posted on the Canvas assignment page.
* Then use those maximum X and Y coordinate values to determine the size you need of a list of lists of the appropriate size. Initialize your list of lists to have '.' as each item. For example, if the maximum value of any X coordinate if 5, and the maximum value of any Y coordinate is 3, then your list of lists would be a list of 4 items, each of which is a list of 6 times containing '.' as follows:
[ ['.', '.', '.', '.', '.', '.'],
['.', '.', '.', '.', '.', '.'],
['.', '.', '.', '.', '.', '.'],
['.', '.', '.', '.', '.', '.'] ]
* From there, you can fill in the letters, replacing the '.' values at the appropriate places in your list of lists. So if point a has the coordinates (4,3), then a would be in the 5th item inside the 1st list, and so on, until you have:
[ ['.', '.', '.', '.', 'a', '.'],
['.', 'b', '.', '.', '.', '.'],
['.', '.', '.', '.', '.', 'c'],
['.', '.', '.', '.', '.', '.'] ]
* Now, using two nested for loops, print the list of lists to the screen to match the output style shown earlier.
This is only a suggestion for how to approach this there are several ways to tackle this problem. Good luck!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
