Pseudocode Guide
Example 1: Output a message on the screen
Python:
print("Hello!")
Cambridge:
OUTPUT “Hello!”
Edexcel:
SEND “Hello!” TO DISPLAY
Example 2: Output a value in a variable
Python:
Data Types:
o String - "Peter”
o Integer - 75
o Real - 6.75
o Boolean - True/False
o Date
Cambridge:
Data Types:
o String - "Peter”
o Char – ‘A’
o Integer - 75
o Real - 6.75
o Boolean - True/False
o Date
Edexcel:
Data Types:
o String - "Peter”
o Character - ‘A’
o Integer - 75
o Real - 6.75
o Boolean - True/False
python:
StudentName = "Peter Mark"
StudentMark = 75
print(StudentName)
print(StudentMark)
Cambridge:
StudentName "Peter Mark"
StudentMark 75
OUTPUT StudentName
OUTPUT StudentMark
Edexcel:
SET StudentName TO “Peter Mark”
SET StudentMark TO 75
SEND StudentName TO DISPLAY
SEND StudentMark TO DISPLAY
Example 3: Output a value in a variable with a message
Python:
print("The Name of student is: ",StudentName)
print(StudentMark,"is the mark of the student")
print(StudentMark,"is the mark of",StudentName)
Cambridge:
OUTPUT "The Name of student is: ",StudentName
OUTPUT StudentMark,"is the mark of the student"
OUTPUT StudentMark,"is the mark of",StudentName
Edexcel:
SEND "The Name of student is: " & StudentName TO DISPLAY
SEND StudentMark & "is the mark of the student" TO DISPLAY
SEND StudentMark & "is the mark of" & StudentName TO DISPLAY
Example 4: Input data to a program
Python:
StudentName = str( input("Enter student name:") )
#str() is used to convert input to string
StudentMark = int( input("Enter student mark:") )
#int() is used to convert input to string
print("Name you have entered", StudentName)
print("Mark you have entered", StudentMark)
Edexcel:
SEND "Enter student name:" TO DISPLAY
RECEIVE StudentName FROM (STRING) KEYBOARD
SEND "Enter student mark:" TO DISPLAY
RECEIVE StudentMark FROM (INTEGER) KEYBOARD
SEND "Name you have entered" & StudentName TO DISPLAY
SEND "Mark you have entered" & StudentMark TO DISPLAY
Cambridge:
OUTPUT “Enter student name:"
INPUT StudentName
OUTPUT "Enter student mark:"
INPUT StudentMark
OUTPUT "Name you have entered", StudentName
OUTPUT "Mark you have entered", StudentMark
Example 5: Performing calculations (Processing)
Python:
Arithmetic Operators:
Addition : +
Subtraction : -
Multiplication : *
Division : /
Power Of : **
ComputerMrk = 75
EnglishMrk = 90
MathsMrk =70
TotalMrk = ComputerMrk + EnglishMrk + MathsMrk
AvgMrk = TotalMrk/3
print("The total marks is ",TotalMrk)
print ("The average is ", AvgMrk)
Edexcel:
Arithmetic Operators:
Addition : +
Subtraction : -
Multiplication : *
Division : /
Power Of : ^
SET ComputerMrk TO 75
SET EnglishMrk TO 90
SET MathsMrk TO 70
SET TotalMrk TO ComputerMrk + EnglishMrk + MathsMrk
SET AvgMrk TO TotalMrk/3
SEND "The total marks is " & TotalMrk TO DISPLAY
SEND "The average is " & AvgMrk TO DISPLAY
Cambridge:
Arithmetic Operators:
Addition : +
Subtraction : -
Multiplication : *
Division : /
Power Of : ^
ComputerMrk 75
EnglishMrk 90
MathsMrk 70
TotalMrk ComputerMrk + EnglishMrk + MathsMrk
AvgMrk TotalMrk/3
OUTPUT "The total marks is ",TotalMrk
OUTPUT "The average is ", AvgMrk
Example 6: Input two numbers and output the difference between the two
Python:
NumOne = int(input("Enter number one:"))
NumTwo = int(input("Enter number two:"))
Difference = NumOne - NumTwo
print("The difference is:",Difference)
Edexcel:
SEND “Enter number one: ” TO DISPLAY
RECEIVE NumOne FROM (INTEGER) KEYBOARD
SEND “Enter number two: ” TO DISPLAY
RECEIVE NumTwo FROM (INTEGER) KEYBOARD
SET Difference TO NumOne - NumTwo
SEND "The difference is:",Difference TO DISPLAY
Cambridge:
DECLARE NumOne, NumTwo, Difference : INTEGER
OUTPUT “Enter number one:"
INPUT NumOne
OUTPUT "Enter number two:"
INPUT NumTwo
Difference NumOne - NumTwo
OUTPUT "The difference is:",Difference
Example 7: Input the price of a chocolate bar and the number of bars purchased.
Calculate the total price for all the bars. Output the total price
Python:
ChocoPrice = float(input("Enter the price of a chocolate:"))
ChocoNum = int(input("Enter the number of chocolates:"))
TotPrice = ChocoPrice * ChocoNum
print("Total price for chocolate bars ", TotPrice)
Edexcel:
SEND “Enter the price of a chocolate” TO DISPLAY
RECEIVE ChocoPrice FROM (REAL) KEYBOARD
SEND “Enter the number of chocolatez” TO DISPLAY
RECEIVE ChocoNum FROM (INTEGER) KEYBOARD
SET TotPrice TO ChocoPrice * ChocoNum
SEND "Total price for chocolate bars " & TotPrice TO DISPLAY
Cambridge:
DECLARE ChocoPrice, TotPrice : REAL
DECLARE ChocoNum : INTEGER
OUTPUT “Enter the price of a chocolate”
INPUT ChocoPrice
OUTPUT “Enter the number of chocolates”
INPUT ChocoNum
TotPrice ChocoPrice * ChocoNum
OUTPUT "Total price for chocolate bars " TotPrice
Example 8: Input the body temperature in Celsius, convert it to Fahrenheit, and output the
Fahrenheit value
Python:
TempC = float(input("Enter the temperature in Celsius:"))
TempF = (TempC * (9/5))+ 32
print("The temperature in Fahrenheit is:", TempF)
Edexcel:
SEND “Enter the temperature in Celsius:” TO DISPLAY
RECEIVE TempC FROM (REAL) KEYBOARD
SET TempF TO (TempC*(9/5))+32
SEND “The temperature in Fahrenheit is:” & TempF TO DISPLAY
Cambridge:
DECLARE TempC, TempF : REAL
OUTPUT “Enter the temperature in celcius:”
INPUT TempC
TempF (TempC*(9/5))+32
OUTPUT “The temperature in Fahrenheit is:” ,TempF
Example 9 : A shop provides a discount of 40% for all the products sold.
Write a program to input the Name of a product, The price of the product
and the number of units sold(Quantity).
Calculate the total price
Calculate the Discount amount
Calculate the final amount to be paid
Output the Product Name, Number of units sold and the final amount
Python:
PName = str(input("Enter the product name "))
PPrice = float(input("Enter the product price "))
PQuantity = int(input("Enter the quantity "))
TotPrice = PPrice * PQuantity
DAmount = TotPrice * 0.4
FinalAmt = TotPrice - DAmount
print("The product sold: ", PName)
print("Number of units: ", PQuantity)
print("Total Amount to Pay: ", FinalAmt)
Cambridge:
DECLARE PName : String
DECLARE PPrice, TotPrice, DAmount, FinalAmt : Real
DECLARE PQuantity : Integer
CONSTANT Discount 0.4
OUTPUT “Enter the product name”
INPUT PName
OUTPUT “Enter the product price”
INPUT PPrice
OUTPUT “Enter the quantity”
INPUT PQuantity
TotPrice PPrice * PQuantity
DAmount TotPrice * Discount
FinalAmt TotPrice – Damount
OUTPUT “The product sold”, PName
OUTPUT "Number of units: ", PQuantity
OUTPUT "Total Amount to Pay: ", FinalAmt
Edexcel:
SET Discount TO 0.4
SEND “Enter the product name” TO Display
RECEIVE PName FROM (String) KEYBOARD
SEND “Enter the product price” TO Display
RECEIVE PPrice FROM (Real) KEYBOARD
SEND “Enter the quantity” TO Display
RECEIVE PQuantity FROM (Integer) KEYBOARD
SET TotPrice TO PPrice * PQuantity
SET DAmount TO TotPrice * Discount
SET FinalAmt TO TotPrice – Damount
SEND “The product sold”, PName TO DISPLAY
SEND "Number of units: ", PQuantity TO DISPLAY
SEND "Total Amount to Pay: ", FinalAmt TO DISPLAY
Example 10 : A Bank provide loans for yearly interest of 15%.
Customers can pay back the loan in selected number of years.
Interest is charged yearly for the amount they borrow.
Customers must pay back the full amount in equal monthly instalments
Write a program to input the Amount to borrow and the number of years to pay
Calculate the Total interest for all the years
Calculate the Total amount to pay (Total interest + Amount borrowed)
Calculate the Amount which the customer must pay monthly.
Output The amount borrowed, and the monthly instalment amount
Python:
BAmount = float(input("Enter the amount to borrow "))
Years = int(input("Enter the number of years "))
TotInterest = (BAmount*0.15)*Years
TotPay = TotInterest + BAmount
MonthlyAmt = TotPay/(12*Years)
print("Amount borrowed: ", BAmount)
print("Monthly instalment amount: ", MonthlyAmt)
Cambridge:
DECLARE BAmount, TotInterest, TotPay, MonthlyAmt : Real
DECLARE Years : Integer
CONSTANT Interest 0.15
OUTPUT "Enter the amount to borrow”
INPUT BAmount
OUTPUT " Enter the number of years”
INPUT Years
TotInterest (BAmount* Interest)* Years
TotPay TotInterest + BAmount
MonthlyAmt TotPay/(12*Years)
OUTPUT "Amount borrowed: ", BAmount
OUTPUT "Monthly instalment amount: ", MonthlyAmt
Edexcel:
SET Interest TO 0.15
SEND "Enter the amount to borrow” TO DISPLAY
RECEIVE BAmount FROM (Real) KEYBOARD
SEND " Enter the number of years” TO DISPLAY
RECEIVE Years FROM (Integer) KEYBOARD
SET TotInterest TO (BAmount* Interest)* Years
SET TotPay TO TotInterest + BAmount
SET MonthlyAmt TO TotPay/(12*Years)
SEND "Amount borrowed: ", BAmount TO DISPLAY
SEND "Monthly instalment amount: ", MonthlyAmt TO DISPLAY
Example 11 :- An athlete is taking part in a marathon.
The race completion time is recorded in Hours,Minutes and Seconds
(If the athlete complete the race in 2hrs 25mins 10secs, it will be
recorded as Hours 2, Minutes 25 and Seconds 10)
Write a program to input the athlete’s name, and the race completion time
In Hours, Minutes and Seconds
Calculate the race completion time is seconds
Output the race completion time in seconds along with the athlete’s name
Python:
AName = str(input("Enter the athlete name: "))
Hours = int(input("Enter race time in Hours: "))
Minutes = int(input("Enter race time in Minutes: "))
Seconds = int(input("Enter race time in Seconds: "))
TotSecs = (Hours*3600)+(Minutes*60)+Seconds
print("Athlete Name: ", AName)
print("Race time in seconds: ",Seconds)
Cambridge:
DECLARE AName : String
DECLARE Hours, Minutes, Seconds, TotSecs : Integer
OUTPUT “Enter the athlete name”
INPUT AName
OUTPUT “Enter race time in Hours:”
INPUT Hours
OUTPUT “Enter race time in Minutes:”
INPUT Minutes
OUTPUT “Enter race time in Seconds:”
INPUT Seconds
TotSecs (Hours*3600)+(Minutes*60)+Seconds
OUTPUT "Athlete Name: ", AName
OUTPUT "Race time in seconds: ",Seconds
Edexcel:
SEND “Enter the athlete name” TO DISPLAY
RECEIVE AName FROM (String) KEYBOARD
SEND “Enter race time in Hours:” TO DISPLAY
INPUT Hours FROM (Integer) KEYBOARD
SEND “Enter race time in Minutes:” TO DISPLAY
INPUT Minutes FROM (Integer) KEYBOARD
SEND “Enter race time in Seconds:” TO DISPLAY
INPUT Seconds FROM (Integer) KEYBOARD
SET TotSecs TO(Hours*3600)+(Minutes*60)+Seconds
SEND "Athlete Name: ", AName TO DISPLAY
SEND "Race time in seconds: ",Seconds TO DISPLAY
Example 12:- A Railway consist of 10 stations identified using numbers 1 to 10.
The train only travels from station 1 to station 10
The fare to travel between two stations is 4$.
A customer can buy one or more tickets for the same journey
Write a program to input the Starting Station Number, the Ending
Station Number and the number of tickets
Calculate Number of stations which the passenger pass.
Calculate the total price which the customer has to pay for the tickets
Python:
CostPerSt = 4 #Constant
StartStNum = int(input("Enter the starting station number "))
EndStNum = int(input("Enter the ending station number "))
NumOfTickets = int(input("Enter the number of tickets "))
NumOfStations = EndStNum - StartStNum
TotPrice = (NumOfStations * CostPerSt)* NumOfTickets
print("Total Price for the tickets ", TotPrice,"$")
Cambridge:
CONSTANT CostPerSt 4 #Constant
OUTPUT “Enter the starting station number”
INPUT StartStNum
OUTPUT “Enter the ending station number”
INPUT EndStNum
OUTPUT “Enter the number of tickets”
INPUT NumOfTickets
NumOfStations EndStNum - StartStNum
TotPrice (NumOfStations * CostPerSt)* NumOfTickets
OUTPUT "Total Price for the tickets ", TotPrice,"$"
Edexcel:
SET CostPerSt TO 4 #Constant
SEND “Enter the starting station number” TO DISPLAY
RECEIVE StartStNum FROM (Integer) KEYBOARD
SEND “Enter the ending station number” TO DISPLAY
RECEIVE EndStNum FROM (Integer) KEYBOARD
SEND “Enter the number of tickets” TO DISPLAY
RECEIVE NumOfTickets FROM (Integer) KEYBOARD
SET NumOfStations TO EndStNum - StartStNum
SET TotPrice TO (NumOfStations * CostPerSt)* NumOfTickets
SEND "Total Price for the tickets ", TotPrice,"$" TO DISPLAY
Example 13:- Student sits for a Computer Science Exam Which consist of 2 papers (Paper1 and
Paper2). Paper 1 is Out of 75 Marks and Paper 2 Out of 50 Marks. Final Mark is
calculated by taking 60% from Paper 1 and 40% from Paper 2
Write a program to Input Student Name, Paper 1 Mark and Paper 2 Mark
Calculate the Final mark of the student
Output the Final Mark along with the student name
Python:
StName = str(input("Enter Student Name"))
P1Mark = int(input("Enter P1 Mark "))
P2Mark = int(input("Enter P2 Mark "))
FinalMark = ((P1Mark/75)*60)+((P2Mark/50)*40)
print("The final mark of ",StName, "is ", FinalMark)
Cambridge:
DECLARE StName : String
DECLARE P1Mark, P2Mark : Integer
DECLARE FinalMark : Real
OUTPUT “Enter Student Name”
INPUT StName
OUTPUT “Enter P1 Mark”
INPUT P1Mark
OUTPUT “Enter P2 Mark”
INPUT P2Mark
FinalMark ((P1Mark/75)*60)+((P2Mark/50)*40)
OUTPUT "The final mark of ",StName, "is ", FinalMark
Edexcel:
SEND “Enter Student Name” TO DISPLAY
RECEIVE StName FROM (String) KEYBOARD
SEND “Enter P1 Mark” TO DISPLAY
RECEIVE P1Mark FROM (Integer) KEYBOARD
SEND “Enter P2 Mark” TO DISPLAY
RECEIVE P2Mark FROM (Integer) KEYBOARD
SET FinalMark TO ((P1Mark/75)*60)+((P2Mark/50)*40)
SEND "The final mark of ",StName, "is ", FinalMark TO DISPLAY
Example 14: Following is to input a number and output whether the number is Positive or
Negative
Python:
Num = int(input('Enter a Number'))
if Num<0:
print('Its a Negative - Number')
else:
print('Its a Positive + Number')
Example 15: Following is to input the student name and computer paper mark(out of 75)
Calculate the mark out of 100
Output whether the student have pass the exam (40% or more)
Or failed the exam (Less than 40%) along with the student name
Python:
Name = input('Enter the student name ')
Mark = int(input('Enter the mark out of 75 '))
MarkPercentage = (Mark/75)*100
if MarkPercentage >= 40:
print(Name, ' Has Pass the Exam')
else:
print(Name, ' Has Failed the Exam')
Example 16: Following program is to input 2 numbers, Calculate the difference between the
two number as a Positive Value and output the difference.
NumOne = int(input('Enter number One '))
NumTwo = int(input('Enter number Two '))
if NumOne > NumTwo:
Difference = NumOne - NumTwo
else:
Difference = NumTwo - NumOne
print('The difference is ', Difference)
Python:
Relational Operators:
== : Equals to
!= : Not Equals to
> : Greater Than
< : Less Than
>= : Greater Than or Equals to
<= : Less Than or Equals to
Example 17: Following program is to input Two Numbers and a Sign (+ or -)
Calculate the Sum of the two numbers if the sign is +
Calculate the Difference of the two numbers if the sign is -
Display the result indicating whether it was + or - performed