http://www.annedawson.net

 

Last updated: Friday 27th February 2015, 10:51 PT, AD

 

Pseudocode

Pseudocode (pronounced SOO-doh-kohd) is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language. Pseudocode is sometimes used as a detailed step in the process of developing a program. It allows designers or lead programmers to express the design in great detail and provides programmers a detailed template (blue print) for the next step of writing code in a specific programming language.

Because pseudocode is detailed yet readable, it can be inspected by the team of designers and programmers as a way to ensure that actual programming is likely to match design specifications. Catching errors at the pseudocode stage is less costly than catching them later in the development process. Once the pseudocode is accepted, it is rewritten using the vocabulary and syntax of a programming language. Pseudocode is sometimes used in conjunction with computer-aided software engineering-based methodologies.



Sponsors:

FYI: There are programs that will convert a given pseudocode language into a given programming language.

 

 

Example Algorithm its respective Pseudocode:

 

Problem: To find the average of 3 numbers

 

Algorithm:

 

   1. Instruct the user to enter the first number

   2. Input the first number

   3. Add the number to a running total

   4. Instruct the user to enter the second number

   5. Input the second number

   6. Add the second number to the running total

   7. Instruct the user to enter the third number

   8. Input the third number

   9. Add the third number to the running total

 10. Divide the total by 3

 11. Print out the result

 

 

 

Pseudocode:

 

total = 0

Display "Enter number 1"

Input number1

total = total + number1

Display "Enter number 2"

Input number2

total = total + number2

Display "Enter number 3"

Input number3

total = total + number3

average = total / 3

Display average

 

 

 

Note: there are no firm rules on the words you choose to represent input, output and processing. For instance, you may use the word write instead of the word Display, or read instead of Input.  Just be consistent.

 

For more examples of pseudocode, check out this pseudocode guide.

 

 

 

 

Program written in the Python 2 language:

 

total = 0.0
number1=float(raw_input("Enter the first number: "))
total = total + number1
number2=float(raw_input("Enter the second number: "))
total = total + number2
number3=float(raw_input("Enter the third number: "))
total = total + number3
average = total / 3
print "The average is " + str(average)

 

 

 



Sponsors:

Program written in the Python 3 language:

 

total = 0.0
number1=float(input("Enter the first number: "))
total = total + number1
number2=float(input("Enter the second number: "))
total = total + number2
number3=float(input("Enter the third number: "))
total = total + number3
average = total / 3
print ("The average is " + str(average))