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

Python Pseudocode

Python uses data types like int, float, bool, and str while pseudocode uses INTEGER, REAL, BOOLEAN, and STRING. Both take input and output similarly using print statements. Control structures like if/else statements and for/while loops function largely the same between the two with some minor syntactic differences. Both Python and pseudocode allow storing data in arrays and manipulating array values through indexing, appending, and deleting elements.

Uploaded by

sky moon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Python Pseudocode

Python uses data types like int, float, bool, and str while pseudocode uses INTEGER, REAL, BOOLEAN, and STRING. Both take input and output similarly using print statements. Control structures like if/else statements and for/while loops function largely the same between the two with some minor syntactic differences. Both Python and pseudocode allow storing data in arrays and manipulating array values through indexing, appending, and deleting elements.

Uploaded by

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

PYTHON vs PSUEDOCODE

IGCSE COMPUTER SCIENCE 0478

Python (case-sensitive) Pseudocode


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

Variable declaration: Variable declaration:


num = int(0) INTEGER num <- 0
value = str(“hi”) STRING value <- “hi”
check = bool(true) BOOLEAN check <- true
deci = float(0.00) 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
ENDIF
PYTHON vs PSUEDOCODE
IGCSE COMPUTER SCIENCE 0478
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 This loop would start from 0 and end at 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 This loop would start from 2 and end at 10
For Loop For Loop

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


/// ///

NEXT val+2
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 vs PSUEDOCODE
IGCSE COMPUTER SCIENCE 0478
Python (case-sensitive) Pseudocode
In order to end the For loop for a condition In order to end the For loop for a condition

for val in range(10): INTEGER x <-0


x = int(input("Enter: ")) FOR val <- 0 to 10
if(x>=0): INPUT “Enter: “, x
continue IF(x >= 0) THEN
else: continue
break ELSE
break

ENDIF

NEXT val
ENDFOR

For loop terminates as soon as you enter a negative For loop terminates as soon as you enter a negative
value otherwise finishes for 10 iterations value otherwise finishes for 10 iterations
While loop While loop

while( condition ): WHILE( condition )


/// ///
ENDWHILE
PYTHON vs PSUEDOCODE
IGCSE COMPUTER SCIENCE 0478
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= int(0) INTEGER counter <- 0


while(counter < 10): INTEGER x <-0
x = int(input("Enter: ")) WHILE (counter < 10)
if(x>=0): INPUT “Enter: “, x
continue IF(x >= 0) THEN
else: continue
break ELSE
break
counter= counter +1
ENDIF
While loop terminates as soon as you enter a negative value
otherwise finishes for 10 iterations counter= counter + 1
ENDWHILE

Subhankar Ganguly – Email [email protected] - Mobile / Whats App +91- 8171775738


PYTHON vs PSUEDOCODE
IGCSE COMPUTER SCIENCE 0478
Python (case-sensitive) Pseudocode
Taking input into the array Taking input into the array

STRING answers[] <- “”


answers= [] FOR index <- 0 to n
for index in range(0, n): #n is arbitrary number INPUT “Enter value: “, value
value= input(“Enter value: “) answers[index] = value
answers.append(value) NEXT index
ENDFOR
Deleting a value from array Deleting a value from array

answers= [1,5,3,0] IF (answers[index] == 0) THEN


remove.answers(0) answers[index] = NULL
print(answers) ENDIF

[1,5,3] [1,5,3]
Reading a value from array Reading a value from array

answers= [1,5,3,0] INTEGER value <- 0


value = answers[2] #gets 5 since it’s on index 2 value <- answers[2]

Writing a value into the array Writing a value into the array

input= input(“Enter value: “) INTEGER input <- 0


answers.append(input) INPUT “Enter value: “, input
answers[index] <- input
Printing whole array Printing whole array

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


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

You might also like