User manual
3. SNAPpy – The Language
SNAPpy is basically a subset of Python, with a few extensions to beer 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
Indentaon is used aer statements that end with a colon (:)
if x == 1:
print "Found number 1"
Indentaon is significant
The amount of indentaon is up to you (4 spaces is standard for Python) but be consistent. The indentaon level
is the thing that disnguishes blocks of code, determining what code is part of a funcon, 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
Idenfiers are case sensive
X = 1
x = 2
Here “X” and “x” are two different variables
Idenfiers must start with a non-numeric character
SNAP® Network Operang System 7