0% found this document useful (0 votes)
5 views

Pseudocode to Python conversion guide v202409

This document provides a guide for converting pseudocode to Python syntax. It includes examples for various programming constructs such as input/output, conditional statements, loops, arrays, and functions. The guide highlights the differences in syntax while maintaining the same logical structure between the two languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Pseudocode to Python conversion guide v202409

This document provides a guide for converting pseudocode to Python syntax. It includes examples for various programming constructs such as input/output, conditional statements, loops, arrays, and functions. The guide highlights the differences in syntax while maintaining the same logical structure between the two languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pseudocode to Python conversion guide

Description Pseudocode Example Python Equivalent


Starting/Ending START There is no start/stop used in Python,
the program OUTPUT "Hello World" so you would just write:
STOP print("Hello World")
Input name = INPUT "Enter your name" name = input("Enter your name: ")
Output OUTPUT "Hello" name print("Hello", name)
If-statement IF age > 18 THEN if age > 18:
(conditional OUTPUT "Adult" print("Adult")
ELSE else:
statement) OUTPUT "Child" print("Child")
ENDIF
Nested If- IF age > 18 THEN if age > 18:
statements OUTPUT "Adult" print("Adult")
ELSE else:
(nested IF age > 12 THEN if age > 12:
conditional OUTPUT "Teenager" print("Teenager")
statements) ELSE else:
OUTPUT "Child" print("Child")
END IF
ENDIF In Python we can combine the else and
if
(see below)

if age > 18:


print("Adult")
elif age > 12:
print("Teenager")
else:
print("Child")
For Loop FOR i = 0 to 5 for i in range(6):
(Count OUTPUT i print(i)
ENDFOR
Controlled)
For Each Loop FOR each item IN ARRAY names for item in names:
(Item in Array) OUTPUT item print(item)
ENDFOR
Creating an Array ARRAY numbers = [1, 2, 3] numbers = [1, 2, 3]

Reading from an OUTPUT numbers[0] print(numbers[0])


Array
Adding to an Add 4 to ARRAY numbers numbers.append(4)
Array
Defining a SUBPROGRAM greet() def greet():
Subprogram OUTPUT "Hello" print("Hello")
ENDSUBPROGRAM
(Function)
Logical Operators AND and
(AND, OR, NOT) OR or
NOT not
i.e. it is the same in Python and
pseudocode, but Python is lowercase
and Pseudocode is capital letters
IF x > 5 AND y < 10 THEN if x > 5 and y < 10:
OUTPUT "True" print("True")
ENDIF

You might also like