Step 1
Hello, robot
Run your first program, print to the console and store values in variables.
Your first program
A program is a list of instructions that Python runs from top to bottom. Press Run (or ⌘/Ctrl + Enter) and anything your program prints shows up in the console.
print("Hello, robot!")
print shows a value in the console. Text goes inside quotes and is called a string. Numbers don't need quotes: print(42) prints 42.
Variables
A variable is a name for a value. The = sign stores the value on its right under the name on its left:
speed = 0.5
color = "red"
From then on, use the name wherever you'd use the value: print(color) prints red. Storing a new value under the same name replaces the old one. Names can use letters, digits and underscores, but can't start with a digit.
print accepts several values separated by commas, and puts a space between them:
print("The", color, "ball") # The red ball
Anything after a # is a comment. Python ignores it, so comments are notes for people reading the code.
Your task
- Give the robot arm a name: store a string in a variable called
name. - The arm has four joints. Store the number
4in a variable calledjoints. - Print a sentence like
Rex has 4 jointswithprint(name, "has", joints, "joints").