Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
5.6. Bob Builds a House
Let’s combine the square and triangle code to create a drawing of a simple house.
Note
The program below has blank lines between the lines of code. The computer ignores the blank lines. We add blank lines to programs to group lines that are working together such as the lines below that draw a square. Often a comment (starts with a #
) is used before a several lines of code to explain the purpose of the code.
Let’s imagine going on to make another partial square along the slope, to create a “chimney.”
Align the program pieces below to make the house and chimney figure above. Draw the square first for the main part of the house, next draw the roof, and finally draw the chimney.
from turtle import *
space = Screen()
bob = Turtle()
---
from turtle import *
space = screen()
bob = turtle() #paired
---
# Make a square
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
---
# Position for roof
bob.right(90)
---
# Position for roof
bob.left(90) #paired
---
# Make a roof
bob.forward(100)
bob.right(-120)
bob.forward(100)
bob.right(-120)
bob.forward(100)
bob.right(-120)
---
# Position for chimney
bob.right(-60)
bob.forward(40)
bob.setheading(90)
---
# Draw chimney
bob.color("red")
bob.forward(30)
bob.right(90)
bob.forward(30)
bob.right(90)
bob.forward(30)
bob.right(90)
Let’s make another square inside the house, to create a “window.”
Align the program pieces below to make the house and window figure above. Draw the square first for the main part of the house, next draw the roof, and finally draw the window.
from turtle import *
space = Screen()
bob = Turtle()
---
from turtle import *
space = screen()
bob = turtle() #paired
---
# Make a square
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
---
# Position for roof
bob.right(90)
---
# Position for roof
bob.left(90) #paired
---
# Make a roof
bob.forward(100)
bob.right(-120)
bob.forward(100)
bob.right(-120)
bob.forward(100)
bob.right(-120)
---
# Position for window
bob.penup()
bob.goto(50,-30)
bob.pendown()
bob.setheading(0)
---
# Draw window
bob.color("red")
bob.forward(30)
bob.right(90)
bob.forward(30)
bob.right(90)
bob.forward(30)
bob.right(90)
bob.forward(30)
Note
Discuss topics in this section with classmates.
You have attempted
of
activities on this page