All of the Keywords are capital in Pseudocode, but lowercase in Python.
a ← b
is the same as a = b
, assigment operator is just a left arrow instead of an equal to symbol.
DISPLAY("Hello World")
is the same as print("Hello World")
RANDOM(a, b)
will translate to
import random
random.randint(a, b)
REPEAT n TIMES
{
(block of statements)
}
translates to
for i in range(n):
(block of statements)
Collegeboard Pseudocode uses a REPEAT UNTIL loop, whereas Python uses a while loop. The difference is that UNTIL runs the loop until a condition is met, but a while loop runs the loop while the condition is true. They are kind of opposites.
FOR EACH item IN aList
{
(block of statements)
}
translates to
for i in aList:
(block of statements)
PROCEDURE procName(parameter1, parameter2, ...)
{
(block of statements)
}
translates to
def funcName(parameter1, parameter2):
(block of statements)
The only main difference is that Python doesn’t need the curly brackets in a loop or function definition.