Python to pseudocode converter
Turn Python code into pseudocode in the style your course uses, from plain English to Cambridge and AP® Computer Science Principles conventions.
SET, IF ... THEN, FOR EACH, OUTPUT: the most widely understood style.
Converting...
Python and its pseudocode, side by side
| Python | Plain | Cambridge | AP® CSP |
|---|---|---|---|
Set a variable total = 0 | SET total TO 0 | total ← 0 | total ← 0 |
Ask for input name = input("Name: ") | INPUT name | INPUT name | name ← INPUT() |
Show output print("Hi", name) | OUTPUT "Hi", name | OUTPUT "Hi", name | DISPLAY("Hi")
DISPLAY(name) |
Decide if x > 10:
print("big")
else:
print("small") | IF x > 10 THEN
OUTPUT "big"
ELSE
OUTPUT "small"
ENDIF | IF x > 10 THEN
OUTPUT "big"
ELSE
OUTPUT "small"
ENDIF | IF (x > 10)
{
DISPLAY("big")
}
ELSE
{
DISPLAY("small")
} |
Count for i in range(1, 6):
print(i) | FOR i FROM 1 TO 5
OUTPUT i
ENDFOR | FOR i ← 1 TO 5
OUTPUT i
NEXT i | i ← 1
REPEAT UNTIL (i > 5)
{
DISPLAY(i)
i ← i + 1
} |
Go through a list for item in items:
print(item) | FOR EACH item IN items
OUTPUT item
ENDFOR | FOR EACH item IN items
OUTPUT item
NEXT item | FOR EACH item IN items
{
DISPLAY(item)
} |
Repeat while while n != 0:
n = n // 10 | WHILE n ≠ 0
SET n TO n DIV 10
ENDWHILE | WHILE n <> 0 DO
n ← n DIV 10
ENDWHILE | REPEAT UNTIL (n = 0)
{
n ← n DIV 10
} |
First item of a list print(scores[0]) | OUTPUT scores[0] | OUTPUT scores[1] | DISPLAY(scores[1]) |
Function def area(w, h):
return w * h | FUNCTION area(w, h)
RETURN w * h
ENDFUNCTION | FUNCTION area(w, h)
RETURN w * h
ENDFUNCTION | PROCEDURE area(w, h)
{
RETURN(w * h)
} |
Which style to pick
- Plain
- Readable English keywords that any teacher or reader follows. Use it when your course names no particular style.
- Cambridge
- The conventions of Cambridge IGCSE Computer Science (0478) and A Level Computer Science (9618): ← for assignment, INPUT and OUTPUT, FOR ... NEXT, WHILE ... DO, CASE OF, OPENFILE and CLOSEFILE for files, & to join text and NUM_TO_STR to turn a number into text.
- AP® CSP
- The AP® Computer Science Principles exam reference sheet: DISPLAY, INPUT(), REPEAT UNTIL, FOR EACH, PROCEDURE and braces. The sheet has no break, continue or files, so those keep their Python names: a sign that the program needs another shape for the exam. Run reference-sheet pseudocode in the pseudocode runner.
- Steps
- Numbered steps from Start to Stop, the way CBSE practical files write an algorithm before the program. A flowchart of the same program is on the Python to flowchart page.
Questions
Is the pseudocode exactly what my exam wants?
It follows each style’s published conventions wherever Python and the style have the same idea. Python also has things these styles lack, such as f-strings, list comprehensions and try, and those stay close to the Python so you can see what to rewrite. Read it through before you hand it in.
Why does the Cambridge style put an IF inside the ELSE instead of ELSE IF?
Cambridge pseudocode has no ELSE IF, so each elif becomes an IF inside the ELSE of the one before. A match statement whose cases are plain values becomes CASE OF instead.
Why does the list index change?
Python counts list positions from 0. Cambridge questions and the AP® Computer Science Principles reference sheet count from 1, so scores[0] becomes scores[1] and the last item, scores[-1], becomes scores[LENGTH(scores)]. A dictionary key in quotes stays as it is.
Does it run my code?
No. It reads the code without running it, so a program that asks for input or never ends converts safely.
Can I convert pseudocode to Python?
Not with this tool. To check reference-sheet pseudocode instead, the pseudocode runner runs it in your browser and shows what it prints.
AP® and Advanced Placement® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website.
Cambridge IGCSE and Cambridge International A Level are qualifications of Cambridge University Press & Assessment, which is not affiliated with this website.