Skip to Main Content
Adventures in Minecraft, 2nd Edition
book

Adventures in Minecraft, 2nd Edition

by David Whale, Martin O'Hanlon
November 2017
Intermediate to advanced content levelIntermediate to advanced
320 pages
6h 57m
English
Wiley
Content preview from Adventures in Minecraft, 2nd Edition

Appendix B

Quick Reference

Table 1 Python input, output, variables

Leaving reminders by using comments

Using constants

# whole-line comment

print("hello") # end-of-line comment

SIZE = 100 # upper case name

Printing to the screen

Reading from the keyboard (Python V3)

print(10) # print a number

print("hello") # print a string

print(a) # print a variable

name = input("your name?")

age = int(input("how old?"))

Storing values in variables

Using Boolean variables

a = 10 # an integer (whole) number

b = 20.2 # a decimal number

message = "hello" # a string

finished = True # a Boolean

high_score = None # no value

anotherGo = True

while anotherGo:

choice = int(input("choice?"))

if choice == 8:

anotherGo = False

Converting strings to (integer) numbers

Converting numbers to strings

size = int(size)

size = size + 1

age = str(age)

print("Your age is " + age)

Calculating with number variables

Calculating absolute values and differences

b = a + 1 # addition

c = a - 1 # subtraction

d = a * 2 # multiplication

e = a / 2 # division

f = a % 2 # remainder after division

absolute = abs(-1) # absolute is 1

difference = abs(x1-x2)

smallest = min(x1, x2)

largest = max(x1, x2)

Table 2 Python loops

Looping

Using counted loops

a = 0

while a<100:

print(a)

a = a + 1

for a in range(10):

print(a) # 0..9

for a in range(5, 50, 5):

print(a) # 5..45 in steps of 5

Looping through all characters in a string

Splitting comma-separated strings

name = "Charlotte"

for ch in name:

print(ch)

line = ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Ultimate Player’s Guide to Minecraft, Third Edition

The Ultimate Player’s Guide to Minecraft, Third Edition

Stephen O’Brien
Minecraft Modding For Kids For Dummies

Minecraft Modding For Kids For Dummies

Sarah Guthals, Stephen Foster, Lindsey Handley

Publisher Resources

ISBN: 9781119439585Purchase book