User manual

3. SNAPpy The Language
SNAPpy is basically a subset of Python, with a few extensions to beer support embedded real-me
programming. Here is a quick overview of the SNAPpy language.
Statements must end in a newline
print "I am a statement"
The # character marks the beginning of a comment
print "I am a statement with a comment" # this is a comment
Indentaon is used aer statements that end with a colon (:)
if x == 1:
print "Found number 1"
Indentaon is significant
The amount of indentaon is up to you (4 spaces is standard for Python) but be consistent. The indentaon level
is the thing that disnguishes blocks of code, determining what code is part of a funcon, or what code repeats
in a while loop, for example.
print "I am a statement"
print "I am a statement at a different indentation level" # this is an error
Branching is supported via “if”/“elif”/“else”
if x == 1:
print "Found number 1"
elif x == 2:
print "Found number 2"
else:
print "Did not find 1 or 2"
y = 3 if x == 1 else 4 # Ternary form is acceptable
Looping is supported via “while”
x = 10
while x > 0:
print x
x = x - 1
Idenfiers are case sensive
X = 1
x = 2
Here “X” and “x” are two different variables
Idenfiers must start with a non-numeric character
SNAP® Network Operang System 7