Hardware Reference
In-Depth Information
To see a tutorial about how to write and play the Welcome Home game, visit the
companion website at www.wiley.com/go/adventuresinminecraft and choose the
Adventure 2 video.
Using if Statements to.Make a
Magic.Doormat
To work out whether your player is standing on the doormat, you will use an if state-
ment to compare your player's position against the position of the doormat. When the
two match, your player will have arrived home.
First, look at how the if statement works; trying it out yourself on the Python Shell
will help you to understand it:
1. Click on the Python Shell. Make sure you click just to the right of the >>>
prompt to make sure that what you type goes in at the right place.
2. Type the following line into the Python Shell, and Python will run it as soon as
you press the Enter key. It won't display anything yet, as all this is doing is stor-
ing the number 20 inside the variable called a :
a = 20
3. Check that the variable a has the correct value in it by typing the following into
the Python Shell:
print(a)
The number 20 should display on the screen.
4. Try out an if statement to see if the value stored in variable a is bigger than 10.
Note that you have to put the colon at the end of the if statement. When you
press Enter at the end of the first line, Python will automatically indent the next
line for you:
if a>10:
print("big")
5. Now press Enter again to tell the Python Shell that you have finished typing the
if statement. You should see the word “big” appear on the Python Shell. To see
what this looks like, see Figure 2-3.
 
Search WWH ::




Custom Search