SELECTION
If/elseif
if pi == 3.14: if pi == 3.14 then
print(“Good”) print("Good")
elif pi == 3: elseif pi == 3 then
print(“ok...”) print("ok...")
else: else
print(“wrong!”) print("wrong!")
endif
Switch/case
match name: switch name:
case "1": case "1":
print("1") print("1")
case "2": case "2":
print("2") print("2")
case default: default:
print("????") print("????")
endswitch
ITERATION
FOR (count-controlled)
for count in range(1,11,2): for count = 1 to 10 step 2
# 11 is exclusive print(count)
print(count) next count
WHILE (condition controlled) - pre-check. Might never run
while continue == “Y” While continue == “Y”
continue = input(“continue?”) continue = input(“continue?”)
endwhile
DO…UNTIL (condition controlled) - post-check. Will run at least once
do
continue = input(“continue?”)
until continue == “N”
STRING MANIPULATION text = “Hello”
What it does PYTHON ERL Return: “Hello”
Count the number of characters in a len(text) text.length 5
string
Extract characters from a string text[1:5] [x:y]: text.substring[1:4] [x:y]: ello
x: first character x: first character
y: last (exclusive) y: number of characters incl x
Slice characters from left/right - text.left(2) / text.right(2) He / lo
Convert string to UPPERCASE text.upper() text.upper HELLO
Convert string to LOWERCASE text.lower() text.lower hello
Concatenate/Join strings + + -
Finds ASCII value of the character ord(“A”) ASC(A) 65
Finds the character corresponding to chr(65) CHR(65) A
the ASCII value