PDF COMPUTING - arghbox

P

dmy

G

Usin

.

YTHON PROGRAMMIN Key Stage 3

COMPUTING

STUDENT REFERENCE AND EXERCISES

PART II

g Minecraft Pi and Codeca

Minecraft Pi Book

Craig Richardson June 13, 2013

This book is licensed under the Creative Commons license of Attribution-NonCommercialShareAlike 3.0 Unported (CC BY-NC-SA 3.0)

You are free:

to Share -- to copy, distribute and transmit the work to Remix -- to adapt the work

Under the following conditions:

Attribution -- You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Noncommercial -- You may not use this work for commercial purposes. Share Alike -- If you alter, transform, or build upon this work, you may distribute the

resulting work only under the same or similar license to this one.

With the understanding that:

Waiver -- Any of the above conditions can be waived if you get permission from the copyright holder.

Public Domain -- Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.

Other Rights -- In no way are any of the following rights affected by the license: ? Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; ? The author's moral rights; ? Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.

Notice -- For any reuse or distribution, you must make clear to others the license terms of this work.

More information can be found on the Creative Commons site:



Disclaimer: Any reference or resemblance to the intellectual property of an individual or organisation is used for educational purposes only.

This book is not affiliated or endorsed by the Raspberry Pi Foundation, Mojang/Minecraft, Codecademy or any organisation mentioned in this book.

Contents

1 Introduction

1

1.1 Using this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Standards Used in this Book . . . . . . . . . . . . . . . . . . . . 2

2 Getting Started

5

2.1 Programming with Python . . . . . . . . . . . . . . . . . . . . . 6

2.1.1 The Minecraft Pi API . . . . . . . . . . . . . . . . . . . . 6

2.1.2 Writing and Running Code . . . . . . . . . . . . . . . . 7

3 Python Syntax

11

3.1 Minecraft Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1.1 Teleport the Player . . . . . . . . . . . . . . . . . . . . . 12

3.1.2 Teleport the Player Precisely . . . . . . . . . . . . . . . 15

3.1.3 Teleportation Tour . . . . . . . . . . . . . . . . . . . . . 16

3.1.4 Stop Smashing Things . . . . . . . . . . . . . . . . . . . 18

3.2 Variables and Data Types . . . . . . . . . . . . . . . . . . . . . . 19

3.2.1 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.2.2 Floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.2.3 Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.2.4 Changing Values of Variables . . . . . . . . . . . . . . . 23

3.3 Whitespace and Statements . . . . . . . . . . . . . . . . . . . . 24

3.3.1 Statements and Line Breaks . . . . . . . . . . . . . . . . 24

3.3.2 Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.4 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

3.4.1 Single Line Comments . . . . . . . . . . . . . . . . . . . 26

3.4.2 Multi-line Comments . . . . . . . . . . . . . . . . . . . . 27

4 Maths Operations

29

4.1 Minecraft Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.1.1 Stacking Blocks . . . . . . . . . . . . . . . . . . . . . . . 30

4.1.2 Super Jump . . . . . . . . . . . . . . . . . . . . . . . . . . 32

i

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download