[OPTIONAL] Lab 7: Making houses using Turtle and nested loops
A Series of Houses/Buildings
NOTE: Download a copy of the lab07
folder from the cs server
to complete this task. Open the file houses.py
in your lab07
folder.
For this part of lab, you will practice writing nested for loops to draw buildings with windows.
The ultimate goal is to create a series of buildings that might look like this (note that colors, height and width of each building are randomly selected):

Let's start with just a single block that we will call a window
. You are given
a function called makeWindow
that creates this, given the size, outer color
and inner color. Here is a sample invocation:
makeWindow(100, 'SlateGray', 'LightSkyBlue')
produces this drawing (on the right is an annotated drawing of the same window):
![]() |
![]() |
Note that the turtle starts and ends in the center of the window, facing East.
Task 1. makeBuilding(rows, columns, size, color1, color2)
This function draws a building consisting of a grid of rows
x columns
windows of size
. Each window has frame color color1
and inner color
color2
.
Recall that you are given the makeWindow
function above that draws a
window for you. Note also that makeWindow
leaves the turtle in the same
location and direction as it was prior to the call to makeWindow
.
This means that if you call makeWindow
, you'll need to move your turtle (leap
comes
in handy here) to a different position before drawing another window. Otherwise,
your windows will draw directly on top of each other and you will only see the topmost one.
Hint: you might consider drawing your buildings from the bottom to the top (it makes it easier to align a row of buildings in the future). Below are two invocations.
makeBuilding(2, 3, 50, 'SlateGray', 'LightSkyBlue') | makeBuilding(5, 2, 50, 'SlateGray', 'LightSkyBlue') |
![]() |
![]() |
Task 2. Write makeRandomColorBuilding(rows, columns, size)
This function draws a building consisting of a grid of rows x columns windows of size. Each window has a randomly selected frame color color1 and inner color color2. For now, ignore the roof (you may get to that later below).
Hints:
- Note that the new version of
turtleBeads.py
includes three random color functions:randomMutedColor
,randomPastelColor
, andrandomVibrantColor
. The images in this lab userandomMutedColor
for the buildings, andrandomPastelColor
for the windows and roofs. - You might consider drawing your buildings from the bottom to the top (it makes it easier to align a row of buildings in the future).
makeRandomColorBuilding(1, 8, 30) | makeRandomColorBuilding(4, 5, 60) |
![]() |
![]() |
Task 3. Write makeRowBuilding(rows, columns, size)
This function draws a building consisting of a grid of rows x columns windows of size. Each row of windows has the same randomly selected frame and inner color. As above, For now, ignore the roof (you may get to that later below).
Hints:
- Think carefully about where to change the window colors to newly chosen random colors.
- The turtle will always start and finish at the center of the lower left window, facing East
makeRowBuilding(6, 3, 50) | makeRowBuilding(2, 5, 50) |
![]() |
![]() |
Task 4. Write makeColumnBuilding(rows, columns, size)
This function draws a building consisting of a grid of rows x columns windows of size. Each column of windows has the same randomly selected frame and inner color. As above, For now, ignore the roof (you may get to that later below).
Hints:
- Think carefully about where to change the window colors to newly chosen random colors.
- The turtle will always start and finish at the center of the lower left window, facing East
makeColumnBuilding(6, 3, 50) | makeColumnBuilding(2, 5, 50) |
![]() |
![]() |
Task 5. Incorporate the roof
You are given a function called drawRoof(windowSize, numCols, rcolor)
.
drawRoof
draws a triangular roof. Assumes starting position is at the upper
left corner of the building, facing East. Note that drawRoof
maintains a position and heading invariant.
Change your makeBuilding
function so that it now draws roofs on each building,
as shown in the drawings below.
makeBuilding(2, 3, 50, 'SlateGray', 'LightSkyBlue') | makeBuilding(5, 2, 50, 'SlateGray', 'LightSkyBlue') |
![]() |
![]() |
Task 6: Make a city scape
Write a function called cityScape
that takes an integer argument that
specifies how many buildings are to be drawn in your city scape. Each
time in your loop, you can invoke one of your functions above that draws
a building. The rows, columns and colors of each building can be randonly
generated (start with a fixed size to make sure it works). You might need
to make some adjustments to ensure that your buildings are neatly aligned
along the bottom most row, as shown in the examples below.
cityScape(4)

cityScape(4)

Table of Contents
- Lab 7 Home
- Part 1: Drawing Memory Diagrams
- Part 2: Memory Diagrams Practice
- Part 3: Code => Memory Diagrams