Review of the Previous Hour
Before we start this new lesson, let's quickly review what we learned in the Hour of Code: Python Basics course:
# print out a string
print('Hello, Buzz Coder!')
# print out a number
print(28)
# assign value to a variable
x = 15
# then print the value
print(x)
Comment
Comments are lines of a code that the computer ignores when you run the program. Comment lines starts with a hash, #
. They are useful when you want to add notes to your program or disable a piece of code that you don't want to run for now.
In the CodeCraft editor, the first line of a file automatically becomes the name of the file, so it's a good idea to write the title of the file there as a comment.
print() function and data types
print()
is one of Python's built-in functions. We can display, or print out, data like a string
or an integer
in the console window.
Assign value to a variable
variable_name = value
You can think of variables
as containers that hold values such as numbers, strings, and other types of data.
Function Basics
All functions have a pair of parentheses following its name. The parentheses may enclose some variables or values as the parameters of the function, or they may be left empty.
Function Calls
To execute, or run, the function, you need to call its name and provide input values for the parameters in the parentheses. If there are no required input parameters, leave the parentheses empty (but they must exist).
Setting up CodeCraft
The following code places one brick block inside CodeCraft 3D world:
from codecraft import Game, Position
game = Game()
materials = game.materials
print(materials)
p = Position(0,2,-10)
game.set_block(p, 17)
Note: if you need to clear all structures in the game world, simply refresh the browser.