COMPUTATIONAL THINKING
Computational thinking is the process of turning a problem into something
that a computer can process and solve.
PARTS OF COMPUTATIONAL THINKING
Abstraction – this is way of filtering information that is not necessary to solve
the problem. Finding important or relevant information. Abstraction makes a
problem easier to solve because you only pick important information.
Abstraction simplifies complex computing problems.
Decomposition - It can also refer to splitting of a problem.
After abstraction and decomposition the program can be developed in a
modular form.
PSEUDOCODES
This is a description of what an algorithm does using keywords, syntax and
identifiers of a particular programming language.
ALGORITHM
An algorithm is a sequence of defined steps that can be used to perform a
specific task.
Algorithm should be easier to understand.
Structured English – this is the use of subset of English language to describe
an algorithm.
VARIABLES
A variable refers to a named memory location that can changed. Variables are
used to store pieces of data that can be used later on in the program. The
assignment operator ‘=‘ is used to assign values to variables. The name of the
variable should be on the left side of the assignment operator. The value
should be on the right hand side. Variable can be assigned to new values.
itemPrice = 9
Bill = itemPrice * 4
Bill = bill + 2
TYPES OF VARIABLES
Global variables – they are available in any part of the program code.
Local variables – they are not available in all part of a program code.
CONSTANTS
Constants are assigned values that do not change during the program
execution. They can only be assigned values before the program start.
e.g:
Const = 3.142
PROGRAMMING LANGUAGE
This is a language that you can to write computer programs. Examples of
programming languages;
       Python
       Visual Basic
       Java
PROGRAMMING BASICS
Declaration of variables
Declaration of variable allows the program to reserve space in the memory. A
is a memory location that stores value that change.
PYTHON
It is a multi paradigm programming language. It supports object oriented
programming and structured programming.
CHARACTERISTICS OF PYTHON
      Every code should be one line.
      Indentation is significant. This is known ‘off side rule’
      Keywords are written in lowercase
      It is case sensitive.
      It is an object oriented language. Everything in python is an object.
      Codes are sliced.
      Programs are interpreted
      WHY DO ERRORS OCCUR
      Why errors occur and how to correct
Error make software not to perform as expected. The following are some of
the reasons;
      The programmer has made a coding mistake
      The specification was to drawn up correctly
      There is a design error
      Poor user design interface
      Hardware failure
TYPES OF ERRORS
      Syntax error
      This is grammatical error.
      Logical errors
      This is an error in the logic of the solution it cause the program to behave differently.
      Run time errors
      They cause the execution to freeze or to crash
DATA STRUCTURES
Data structures are used to organize multiple data values and save them under
a single name.
DATA TYPES
Collection of data values. Programming languages store data using different
data types. A data type describes what the data is and how it can used by the
computer. Examples of data types
 Data type                          Characteristics                     Examples
 Integer int                        Whole numbers                       6
 Real / float                       Numbers with decimal places         0.15
 Boolean                            Can only take one of two            True/false ,1/0, y/n
                                    values
 Character                          A single letter , number or         “A”
                                    symbol
 String                             Collection of character             “Hello Myles”
OPERATORS
An operator is a symbol that carries our particular function. A function is
module that performs a specific task. Arithmetic operators take two or more
numbers and perform a calculation.
 Function                  Operator                   Examples                  Result
 Addition                  +                          5+3                       8
 Subtraction               -                          10-2                      8
 Division                  /                          20/4                      5
 Multiplication            *                          6*7                       42
 Exponentiation /          ^ or **                    10^3                      1000
 powers
Assignment - this is the process of associating a value with a name. The
name can also be referred to as an identifier. The symbol for an assignment is
the equal sign (=)
Sequence – the order or the steps in which instructions occur or performed.
Selection – the different paths that the program takes as it is being
Performed.
Repetition – a sequence of steps performed a number of times. This can also
be referred to as looping or iteration.
COMPARISON OPERATORS
These operators are used to compare two values. The comparison will then
result into true or false values.
 Operator                   Meaning                    Evaluates to true        Evaluates to false
 ==                         Is equal to                5==5                     5==8
 != or <>                   Is not equal to            6!=7                     6!=6
 <                          Is less than               4<10                     3<2
 >                          Is greater than            15>9                     10>12
 <=                         Is less than or equal to   7<=8                     11<=10
 >=                         Is greater than or         3>=3                     9>=12
                            equal to
BOOLEAN OPERATORS
They take Boolean input and give Boolean output. There are three Boolean
operators AND, OR and NOT. These operators can be used in logic.
 Operator                           Evaluates to true if;              Evaluates to false if;
 AND                                Both inputs are true:              Either input is false:
                                    3<5 AND 2>1                        4<5 AND 10>20
 OR                                 Either input is True:              Both inputs are False:
                                    1>8 or 2==2                        1==8 OR 2<2
 NOT                                Input is False:                    Input is True:
                                                                       NOT(10>6)
                                    NOT(5>8)
STRINGS
Strings are written in double or single quotation marks. Strings could be joined
together and this method is known as concatenation
    1. String1 = “foot”
    2. String2 = “ball”
    3. newString = foot + ball
    4. Print(newString)
INPUTS AND OUTPUTS
Inputs and outputs are how data is communicated between the program and
the user.
Inputs are the data that a computer receives and outputs are how the
computer sends the back to the user.
age = INPUT (“Enter your age”)
CASTING
Casting function allows the changing of data values. Examples of casting values;
INT(); REAL(), STR()
tempA =20
tempB = REAL(tempA)
tempC= STR(tempA)
PROGRAM FLOW -SEQUENCE
There are three main program flows.
Sequence
Selection
Iteration / looping
SEQUENCE
This is where an instruction is carried out in the order of one after another.
There is only one root to follow there is no decision or repeat/ looping.
SELECTION
This is where decisions are made that affect which instructions are carried are
carried out.
ITERATION / LOOPS
This is where a certain set of instructions are repeated. The number of times
that a condition is repeated can fixed depending on a condition.
SELECTION
Selection algorithm involves a decision. The outcome decides the next
instruction.
It uses IF statements if a condition is true or false and carry out different
actions depending on the outcome.
Flowchart
NESTED LOOP
This is a loop containing another loop.
ITERATION
Iteration statements repeats codes. You don’t have to type the codes over and
over again. FOR loops are used for iteration.
FUNCTIONS
When a function is called it does something with the return value.
ARITHMETIC OPERATORS
 Function                    Operator              Examples                 Result
 Addition                    +                     5+3                      8
 Subtraction                 -                     10-2                     8
 Division                    /                     20/4                     5
 Multiplication              *                     6*7                      42
 Exponentiation /            ^ OR **               10^3                     1000
 powers
 Modulus                     MOD
 Integer division            %
ORDER OF PRECEDENCE
The following is the order of precedence. The order of precedence defines
the order of calculations:
       Brackets (parenthesis)
       Exponentiation
       Multiplication
       Division
       Addition
       Subtraction
OUTPUTTING INFORMATION TO THE
SCREEN
print (<print list>)
print (“Hello world`)
GETTING / PROMPTING INPUT FROM THE
USER
A = input ( “Enter a number”)
COMMENTS
Comments are used to explain how the programs works.
# This is my comment
DATA TYPES
 Description of data                           Python
 Whole signed numbers                          int
 Decimal numbers                               float
 A single character                            char
 Sequence of characters                        string
 Logical values                                Boolean
BOOLEAN EXPRESSION
 Operation                        Python
 Equal                            ==
 Not equal                        !=
 Greater than                     >
 Less than                        >
 Greater than or equal to         >=
 Less than or equal to            >=
PROCEDURES
Procedures do not return values
FUNCTIONS
They perform specific tasks.