0% found this document useful (0 votes)
6 views6 pages

Python Pseudocode Examples and Syntax

The document provides a comparison between pseudo code and Python code for various programming constructs, including output statements, variable declarations, conditional statements, case statements, loops, and functions. It illustrates how to implement basic programming logic in both languages. The examples cover operations such as calculating the volume of a cylinder, string manipulation, and defining procedures and functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Python Pseudocode Examples and Syntax

The document provides a comparison between pseudo code and Python code for various programming constructs, including output statements, variable declarations, conditional statements, case statements, loops, and functions. It illustrates how to implement basic programming logic in both languages. The examples cover operations such as calculating the volume of a cylinder, string manipulation, and defining procedures and functions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PSEUDO CODE PYTHON

OUTPUT "Hello World" print ("Hello World")

DECLARE FirstVar : INTEGER FirstVar = 20


DECLARE SecondVar : INTEGER SecondVar = 30
FirstVar <-- 20 FIRSTCONST = 500
SecondVar <-- 30 SECONDCONST = 100
CONSTANT FirstConst <-- 500 or
CONSTANT SecondConst <--100 FirstVar, SecondVar = 20, 30
FirstConst, SecondConst = 500,100

DECLARE radius : REAL radius = float(input("Please enter the radius of


OUTPUT "Please endter the radius of the the cylinder "))
cylinder"
INPUT radius

OUTPUT "Volume of the cylinder is", volume print("Volume of the cylinder is ", volume)

IF Age > 17 if Age > 17:


THEN print ("You are an adult")
OUTPUT "You are an adult"
ENDIF

1
PSEUDO CODE PYTHON
IF Age > 17 if Age > 17:
THEN print ("You are an adult")
OUTPUT "You are an adult" else:
ELSE print ("You are a child")
OUTPUT "You are a child"
ENDIF

CASE OF OpValue if OpValue == "+":


"+" : Answer ¨ Number1 + Number2 Answer = Number1 + Number2
"-" : Answer ¨ Number1 - Number2 elif OpValue == "-":
"*" : Answer ¨ Number1 * Number2 Answer = Number1 - Number2
"/" : Answer ¨ Number1 / Number2 elif OpValue == "*":
OTHERWISE OUTPUT "Please enter a valid Answer = Number1 * Number2
choice" elif OpValue == "/":
ENDCASE Answer = Number1 - Number2
else: print("invalid operator")

FOR Counter <-- 1 TO 11 STEP 2 for Counter in range (1,11,2):


OUTPUT Counter print(Counter)
NEXT Counter

2
PSEUDO CODE PYTHON
WHILE TotalWeight < 100 DO while TotalWeight < 100:
TotalWeight = TotalWeight + Weight TotalWeight = TotalWeight + Weight
ENDWHILE

LENGTH("Computer Science") len("Computer Science")


LENGTH(MyString) len(MyString)

DECLARE MyString : STRING MyString = "Information Technology "


MyString <-- "Information Technology" print ("Computer Science"[9:16])
OUTPUT SUBSTRING("Computer Science", 10, 7) print (MyString [12:16])
OUTPUT SUBSTRING(MyString, 10, 7)

DECLARE MyString : STRING MyString ="Information Technology"


MyString <-- "Information Technology" print ("Computer Science".upper())
OUTPUT UCASE("Computer Science") print ([Link]())
OUTPUT UCASE(MyString)

DECLARE MyString : STRING MyString ="Information Technology"


MyString <-- "Information Technology" print ("Computer Science".lower())
OUTPUT LCASE("Computer Science") print ([Link]())
OUTPUT LCASE(MyString)

3
PSEUDO CODE PYTHON

4
PSEUDO CODE PYTHON

PROCEDURE Stars def Stars():

OUTPUT"************" print("************")

ENDPROCEDURE Stars()

CALL Stars

5
PSEUDO CODE PYTHON
PROCEDURE Stars (Number : INTEGER) def Stars(Number):
DECLARE Counter : INTEGER for counter in range (Number):
FOR Counter ← 1 TO NUMBER print("*", end = "")
OUTPUT "*" Stars (7)
NEXT Counter
ENDPROCEDURE
CALL Stars (7)

DECLARE MyTemp : REAL def Celsius(Temperature):


MyTemp <-- 7 return (Temperature - 32) / 1.8
FUNCTION Celsius (Temperature : REAL) print (Celsius(7))
RETURNS REAL
RETURN (Temperature - 32) / 1.8
ENDFUNCTION
MyTemp ← Celsius(MyTemp)

OUTPUT MyTemp

You might also like