PROGRAMMING
PYTHON
DATA TYPES
Integer:whole numbers that range from -2,147,483,647 to 2,147,483,647
Real: includes allows to work with Decimal numbers. For e.g 0.5,0.8
Char: single alphabetic character e.g a,B,c,D
String: allows to enter sentences, words or phrases
Boolean: two options for e.g true, false or 0 and 1
VARIABLES AND CONSTANTS
• Variable:Python variables are simply containers for storing data values. Height, age,
income, province or country of birth, grades obtained at school and type of housing are all
examples of variables
• Constant:a number that has a fixed value in a given situation or universally or that is
characteristic of some substance or instrument. For e.g number of people that can enter a
certain ride
VARIABLE NAMING RULES
1.A variable name must start with a letter or the underscore character.
2.A variable name cannot start with a number.
3.A variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ )
4.Variable names are case-sensitive (age, Age and AGE are three different variables)
OPERATORS
special symbols place some sort of function to be performed
Arithmetic operators. Types of operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
TYPES OF STATEMENTS
Input/output: to enter or show data
Loops: to repeat a task
Function:a set of coded instructions that tell a computer how to run a program or
calculation
Procedures: like a function but returns a value
QUESTIONS
• Make a program that adds two numbers.
• Make a programs that calculates average of two numbers
• Make a program that enters 4 numbers adds the first and fourth number,
multiplies the result with second number, and finally subtracts the third
number from the result.
• Make a program that compares the age(in months,whole number), height and
weight of two friends
HOMEWORK
• Make a program that multiplies two numbers
• Make a program that divides two numbers
PSEUDOCODE
• What is pseudocode
In computer science, pseudocode is a plain description of the steps in an algorithm
or another system. Pseudocode often uses the structural of a normal programming
language, but is intended for human reading rather than machine reading.
• Why use pseudocode
It provides programmers with a detailed template for writing code in a specific
programming language. Because pseudocode is written in readable format, it can be
inspected by a team of designers and programmers as a way to ensure that the actual
programming will match design specifications.
STATEMENT USED IN PSUEDOCODE
• DECLARATION
declare
• Input
input
• Output
output
LOOPS
• Repeat/iterate
Count controlled
Conditional
Pre conditional
post conditional
COUNT CONTROLLED LOOPS
• used when the number of iterations to occur is already known. A
count-controlled loop is so called because it uses a counter to keep
track of how many times the algorithm has iterated.
Examples
For loops
CONDITIONAL LOOPS
• A conditional loop keeps repeating until a specific condition is
met.It has two types:
Pre conditional
Post conditional
PRECONDITIONAL LOOPS
• A pre-condition to a function is a condition that must be true
before entering the function.
For example:
While loops
POST CONDITIONAL LOOPS
• This form of repetition will check the condition after the
commands have been executed, initiating another execution of the
loop if the condition is not met.
For example
Repeat until