0% found this document useful (0 votes)
2 views8 pages

Computational Thinking and Programming

The document provides an overview of pseudocode, its purpose, and its application in programming, emphasizing its role in designing algorithms before coding. It includes definitions of key terms, flowchart shapes, and examples of pseudocode alongside Python code to illustrate the translation process. Additionally, it highlights the importance of variables and input/output operations in programming.

Uploaded by

levi makokha
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)
2 views8 pages

Computational Thinking and Programming

The document provides an overview of pseudocode, its purpose, and its application in programming, emphasizing its role in designing algorithms before coding. It includes definitions of key terms, flowchart shapes, and examples of pseudocode alongside Python code to illustrate the translation process. Additionally, it highlights the importance of variables and input/output operations in programming.

Uploaded by

levi makokha
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
You are on page 1/ 8

COMPUTATIONAL THINKING AND PROGRAMMING

Pseudocode

Learning Objectives

• Understand the purpose and rules of pseudocode.

• Be able to read and follow algorithms written in pseudocode.

• Recognize how pseudocode is used to design programs before coding.

Terms used

Term Meaning

A way to describe an algorithm


Pseudocode without using a specific programming
language.

A named space in memory to store


Variable
values that can change.

Assignment Giving a value to a variable.

Data received from or sent to the


Input/Output
user.

String A sequence of characters (text).

Concatenation Joining strings together.

Symbols like +, -, *, / used in


Arithmetic Operator
calculations.

Rules about how code must be


Syntax
written.
Flowchart Shapes

These are standard shapes used in flowcharts to represent different types of


operations:

Shape Purpose

Oval Start or Stop

Parallelogram Input or Output

Rectangle Process (a calculation or assignment)

Diamond Decision (e.g., Yes/No question)

Python code

numDays = int(input("Enter the number of days"))

numHours = int(input("Enter the number of hours"))

numMins = int(input("Enter the number of minutes"))

totalHours = (numDays * 24) + numHours

totalMins = numMins + (totalHours * 60)

print("The total number of minutes is", totalMins)


What the above code does:

Step Code line Description

Asks the user to input a


1 numDays = int(input(...)) number of days, stores it
in a variable numDays.

Asks for hours and stores


2 numHours = int(input(...))
in numHours.

Asks for minutes and


3 numMins = int(input(...))
stores in numMins.

totalHours = (numDays * Converts days into hours


4
24) + numHours and adds extra hours.

Converts all hours into


totalMins = numMins +
5 minutes and adds the
(totalHours * 60)
remaining minutes.

Outputs the total


6 print(...) number of minutes to
the screen.

Variables Used

✓ numDays: stores number of days

✓ numHours: stores number of hours

✓ numMins: stores number of minutes

✓ totalHours: intermediate variable to hold total hours

✓ totalMins: final output in minutes

Note:

Variables store data that can change during program execution.


You use input to get data from the user and output (print) to display results.
What does the program do?

a) It asks the user to enter a number of days, hours, and minutes.


b) It converts all this time into minutes ,then displays the total

What is Pseudocode?

• Pseudocode is a method used to design programs before writing actual


code.

• It combines the words "pseudo" (false) and "code" (programming


instructions).

• Pseudocode uses English-like language that looks similar to code but isn’t
real code.

Purpose of Pseudocode

• Helps programmers plan logic clearly before coding.

• Easier to understand for both technical and non-technical people.

• Does not follow strict syntax rules, unlike real programming languages.

• Can be converted into a high-level language like Python.

Flowchart to Pseudocode to Python


It shows a process of:

a) Taking two inputs

b) Adding them

c) Outputting the result

Flowchart

• Start → Input num1 → Input num2 → Process (answer = num1 + num2) →


Output answer → Stop

Pseudocode

INPUT num1

INPUT num2

answer ← num1 + num2

OUTPUT answer
Python

num1 = int(input())

num2 = int(input())

answer = num1 + num2

print(answer)

What is a Variable?

• A variable is a named location in memory to store values.

• Used to hold user input, temporary results, or final answers.

• Can be reused in pseudocode just like in real code.

Programmers Translating Pseudocode

The image below illustrates a team of programmers working together, translating


pseudocode into real code like Python.
Note that Pseudocode is:

✓ Language-independent.It can be read and converted to any


programming language.

✓ No formal syntax. Write it in plain English-like structure.

✓ Not real code, so won’t run on a computer until translated.

Ways to Write Input in Pseudocode

Examples (all are valid):

❖ name ← INPUT

❖ name = INPUT

❖ INPUT "Enter your name", name

❖ name = input("Enter your name")

❖ READ name

❖ name = Console.Read

What All Input Statements Have in Common

- They all take input from the user


- They all use a variable to store data
- Some versions show the user a message (prompt)
- Some use = or ←, and some don’t use either

Differences in Input Statements

• Commands may vary (INPUT, READ, input())

• Use of assignment (= or ←) differs

• Some include a message prompt, others don’t


Important Features of Pseudocode

a) Uses clear steps that can be translated into real code.

b) Helps you understand logic without focusing on syntax errors.

c) Must include:

✓ Commands/keywords (INPUT, OUTPUT, IF, WHILE)

✓ Variables to store data

✓ Mathematical/logical operations (e.g. +, -, *, /, >, <, ==)

Example Comparison Table

English Statement Pseudocode Python Code

Take user's name as name = input("Enter your


INPUT name
input name")

WHEN AND WHY DO WE USE PSEUDOCODE

You might also like