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

Python V Pseudocode (OL - IGCSE CS)

Uploaded by

GamingVlog Box
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Python V Pseudocode (OL - IGCSE CS)

Uploaded by

GamingVlog Box
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PYTHON vs PSUEDOCODE CHEAT SHEET

IGCSE COMPUTER SCIENCE 0478

Python (case-sensitive) Pseudocode


Data Types: Data Types:
int, float, bool, str INTEGER, REAL, BOOLEAN, STRING

Variable declaration (Python automatically detects) Variable declaration:


num = 0 #int INTEGER num <- 0
value = “hi” #str STRING value <- “hi”
check = true #bool BOOLEAN check <- true
deci = 0.00 #float REAL deci <- 0.00

Input and output: Input and output:


num = int(input(“Enter value: “)) INPUT “Enter value: “, num
schoolName = str(input(“Enter school name: “)) INPUT “Enter school name: “, schoolName
print(num) PRINT NUM
print(“Value entered: “, schoolName) PRINT “Value entered: “, schoolName
If condition: If condition:

if( condition ): IF( condition ) THEN


/// ///

elif( another condition ): ELSE IF ( condition ) THEN


/// ///

else: ELSE
/// ///

ENDIF
Python (case-sensitive) Pseudocode
For Loop For Loop

for val in range(10): FOR val <- 0 to 10


/// ///
NEXT val
ENDFOR

This loop would start from 0 and end at 9 (a total This loop would start from 0 and end at 10
count of 10)
For Loop For Loop

for val in range(2,10): FOR val <- 2 to 10


/// ///

NEXT val
ENDFOR

This loop would start from 2 and end at 9 (range This loop would start from 2 and end at 10
function in Python works till n-1)
For Loop For Loop

for val in range(1,10,2): FOR val <- 1 to 10 STEP 2


/// ///

NEXT val
ENDFOR

This loop would start from 1, end at 10 and This loop would start from 1, end at 10 and
increment the loop variable var by 2 instead of 1. increment the loop variable var by 2 instead of 1.
Python (case-sensitive) Pseudocode
In order to end the For loop for a condition In order to end the For loop for a condition
(Pseudocode does not have break or continue keywords)
for val in range(10):
x = int(input("Enter a value: ")) DECLARE x AS INTEGER
if(x>=0):
continue REPEAT
else: INPUT(“Enter a value: “), x
break UNTIL(x<0)

OR

INPUT(“Enter a value: “), x


WHILE(x >= 0)
INPUT(“Enter a value: “), x
ENDWHILE

For loop terminates as soon as you enter a negative


value otherwise finishes for 10 iterations
While loop While loop

while( condition ): WHILE( condition )


/// ///
ENDWHILE
Python (case-sensitive) Pseudocode
In order to end the while loop for a condition In order to end the while loop for a condition

counter= 0 INTEGER counter <- 0


while(counter < 10): INTEGER x <-0
x = int(input("Enter a value: "))
if(x>=0): WHILE(counter < 10)
continue REPEAT
else: INPUT(“Enter a value: “), x
break UNTIL(x<0)

counter= counter +1 counter <= counter + 1

ENDWHILE

While loop terminates as soon as you enter a While loop ends after 10 iterations and Repeat
negative value otherwise finishes for 10 iterations Until keeps repeating until user enters a value<0
Python (case-sensitive) Pseudocode
Taking input into the array Taking input into the array

DECLARE answers:ARRAY[1:5] of INTEGER


answers= [0,0,0,0,0] answers= [0,0,0,0,0]
for index in range(0, 5): #n is size of array FOR index <- 1 to 5
value= input(“Enter value: “) INPUT “Enter value: “, value
answers[index] = value answers[index] = value
NEXT index
ENDFOR
Reading a value from array Reading a value from array

answers= [1,5,3,0] DECLARE value as INTEGER


value = answers[2] #gets 3 since Py index start from 0 value <- answers[2]
print(value) PRINT value
Writing a value into the array Writing a value into the array

value= input(“Enter value: “) DECLARE value AS INTEGER


answers[index] = value INPUT “Enter value: “, value
answers[index] <- value
Printing whole array Printing whole array (N is size of array)

for index in range(len(answers)): FOR index <- 0 to N


print( answers[index] ) PRINT answers[index]
NEXT index
ENDFOR

You might also like