To start this assignment, download this zip file.
Lab 6a — Grouping
Reminder, you should work in teams of 2 or 3 when solving the lab problems. Learning to code together is an important part of this class.
Download the zip file for this lab, located above. This zip file has code that
you will use for this assignment. Extract the files and put them in your
directory in a folder called
We have given you code in
practice.py that provides some simple practice with
There are instructions in the code asking you to do the following:
Copy and paste a function for creating an empty grid
Copy and paste a function for printing a grid
Create an empty grid, 5 rows and 8 column; use a space as the value for the grid
Put a ’🦋’ in (1, 1) — row 1 — column 1
Put a ’🦖’ in (0, 7)
Put a ’🐳’ in (4, 2)
Print the grid
You can see the guide on grids for help.
After you finish and run the program, it should print:
🦖 🦋 🐳
Discuss with the TA
- How did you write this code? Show a solution and discuss.
- Is there anything you don’t understand about grids?
We have a partially-written program in
drawing.py that will use a grid to
create a simple drawing program. Following are the functions for you to
Printing the grid
First write the
def print_grid(grid, between=' '): """ Print all the items in the grid, so that it looks like a grid. <between> is the character between columns, by default a space """ # Write code here pass
Notice that there is an important difference between this function and the one
included in the guide on grids. This function takes a new
between. This character should be used as the character to
print in between columns.
You can copy and paste the function from the guide and then modify it to have this new functionality, which will let you specify the character to use in between columns when printing a grid.
Drawing in one row and column
Next write the
def draw(grid, row, column, character): """ <grid> - a grid <row> - a row number (integer) <column> - a column number (integer) <character> - a character Modifies the grid so that <row>,<column> contains <character>. Does not modify the grid if <row> is too small or too large. Also does not modify the grid if <column> is too small or too large. """ # Write code here pass
This is similar to the practice problem, except you need to be sure the row and
column you are given are actually in the grid. We did something like this for
has_value() function in the guide.
Drawing on the grid
Finally, write the
def draw_on_grid(grid): """ This function allows a user to draw on a grid. It does the following: - prints the grid, using '' as the character between columns - lets the user enter coordinates in "row, column" format, e.g.: 2, 3 - draws a 🟦 at each coordinate they enter - stops when they enter nothing """ # Write code here pass
This function needs to loop, take user input, and then modify the grid.
Discuss with the TA
- How did you implement these functions? Show a solution and discuss.
- Make sure everyone understands every line of code we supplied.
To finish this lab and receive a grade, take the canvas quiz.
We are providing a solution so you can check your work. Please look at this after you complete the assignment. :-)