Cambridge IGCSE 0478 ยท A-Level 9618 ยท IB CS
Python to Pseudocode
Converter Guide
Know Python but need to write Cambridge pseudocode? Here's the complete mapping โ side by side, concept by concept.
๐ก PseudoStudio IDE Tip: Our online compiler also has a built-in Python-to-Pseudocode conversion tool. Open the IDE and paste your Python code to get an instant pseudocode translation.
Try the converter โ
Quick Reference Table
| Concept | Python | Cambridge Pseudocode |
|---|---|---|
| Print / Output | print("Hello") | OUTPUT "Hello" |
| Input | name = input("Enter name: ") | INPUT name |
| Assign variable | x = 5 | x โ 5 |
| Declare variable | (not needed) | DECLARE x : INTEGER |
| Integer division | x // y | x DIV y |
| Modulus | x % y | x MOD y |
| Not equal | x != y | x <> y |
| FOR loop | for i in range(1, 6): | FOR i โ 1 TO 5 ... NEXT i |
| WHILE loop | while x < 10: | WHILE x < 10 ... ENDWHILE |
| IF statement | if x > 5: | IF x > 5 THEN ... ENDIF |
| IF...ELSE | if x > 5: ... else: | IF x > 5 THEN ... ELSE ... ENDIF |
| List (Array) | scores = [0] * 5 (0-indexed) | DECLARE scores[1:5] : INTEGER (1-indexed) |
| String length | len("Hello") | LENGTH("Hello") |
| Substring | "Hello"[1:4] | SUBSTRING("Hello", 2, 3) |
| Upper case | "hello".upper() | UCASE("hello") |
| Function | def myFunc(x): return x*2 | FUNCTION myFunc(x : INTEGER) RETURNS INTEGER ... ENDFUNCTION |
| Procedure | def myProc(x): print(x) | PROCEDURE myProc(x BYVAL : INTEGER) ... ENDPROCEDURE |
Side-by-Side Examples
๐ Python
# Variables & output name = input("Enter name: ") age = int(input("Enter age: ")) print("Hello,", name) print("Age:", age)
๐ Cambridge Pseudocode
// Variables & output DECLARE name : STRING DECLARE age : INTEGER INPUT name INPUT age OUTPUT "Hello,", name OUTPUT "Age:", age
๐ Python โ FOR Loop
for i in range(1, 11): print(i * i)
๐ Pseudocode โ FOR Loop
DECLARE i : INTEGER FOR i โ 1 TO 10 OUTPUT i * i NEXT i
๐ Python โ WHILE Loop
count = 1 while count <= 5: print(count) count += 1
๐ Pseudocode โ WHILE Loop
DECLARE count : INTEGER count โ 1 WHILE count <= 5 OUTPUT count count โ count + 1 ENDWHILE
๐ Python โ IF/ELSE
score = int(input("Score: ")) if score >= 70: print("Pass") else: print("Fail")
๐ Pseudocode โ IF/ELSE
DECLARE score : INTEGER INPUT score IF score >= 70 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
๐ Python โ List (Array)
scores = [0] * 5 # 0-indexed for i in range(5): scores[i] = int(input()) print(scores[0]) # first item
๐ Pseudocode โ Array (1-indexed)
DECLARE scores[1:5] : INTEGER DECLARE i : INTEGER FOR i โ 1 TO 5 INPUT scores[i] NEXT i OUTPUT scores[1] // first item
โ ๏ธ Key difference โ Array indexing: Python lists start at index 0. Cambridge pseudocode arrays start at index 1. This is one of the most common mistakes students make when translating between the two.
๐ Python โ Function
def square(n): return n * n result = square(5) print(result)
๐ Pseudocode โ FUNCTION
FUNCTION Square(n : INTEGER) RETURNS INTEGER RETURN n * n ENDFUNCTION DECLARE result : INTEGER result โ Square(5) OUTPUT result
Learn More Pseudocode: