Convert between Python and WJEC-style pseudocode. Uses actual Appendix B conventions from the specification.
Designed with the WJEC specification in mind โ Appendix B| Concept | Python | WJEC Pseudocode |
|---|---|---|
| Output | print("hello") | OUTPUT "hello" |
| Input | x = input("prompt") | x โ USERINPUT |
| Assignment | x = 5 | x โ 5 |
| If | if x > 5: | IF x > 5 THEN |
| Else | else: | ELSE |
| Else if | elif x > 3: | ELSEIF x > 3 THEN |
| End if | (indentation) | ENDIF |
| For loop | for i in range(1,11): | FOR i โ 1 TO 10 |
| End for | (indentation) | ENDFOR |
| While | while x > 0: | WHILE x > 0 |
| End while | (indentation) | ENDWHILE |
| Function def | def add(a, b): | FUNCTION add(a, b) |
| Return | return result | RETURN result |
| End function | (indentation) | ENDFUNCTION |
| Array access | arr[0] | arr[0] |
| Length | len(arr) | LENGTH(arr) |
| String concat | "hi" + name | "hi" & name |
| And / Or / Not | and / or / not | AND / OR / NOT |
| Int conversion | int(x) | INT(x) |
| String conversion | str(x) | STRING(x) |
| Open file read | f = open("f.txt","r") | OPENREAD("f.txt") |
| Open file write | f = open("f.txt","w") | OPENWRITE("f.txt") |
| Read line | line = f.readline() | line โ READLINE() |
| Write line | f.write(data) | WRITELINE(data) |
| Close file | f.close() | CLOSEFILE() |