Hardware Reference
In-Depth Information
To build lots of houses, you need to add a
for
loop to your program as follows:
1.
So that you don't break your existing
buildHouse2.py
program, use File
➪
Save As from the menu and save a new file called
buildStreet.py
.
2.
At the end of the program, add a
for
loop above the final
house()
along with a
line that changes the
x
position that the house is built at. Each house is built
SIZE
blocks away from the previous house. The new lines are marked in bold:
for h in range(5):
house()
x = x + SIZE
Save your program, then move to a place in the Minecraft world where there is a bit of
space, and run the program. As shown in Figure 3-7, you should get a huge street of
five houses as far as the eye can see! Walk your player into each of the houses and make
sure that they have been built properly.
FIGURE.3-7:
A street of five identical houses built automatically with a Python
program
CHALLENGE
How could you modify your loop so that instead of building your houses in a
row, it builds them upwards to create a huge tower block? Try it. Turn your tower
block builder into a function called
tower()
and then use a loop to build a few
tower blocks inside your Minecraft world.