Programming Logic in Python
Planning of what is to be expressed and how to express to the system
Programming Logic Building Tools:
1. Algorithm
2. pseudocode
3. Flow Chart
Algorithm
step by step solution of a given problem written in simple human understandable language.
Ex1:
Write algorithm to ask the system to store value 25 in its memory and display the value on the screen.
Algorithm:
1. start your program
2. reserve some amount of memory in your RAM to store a number later.
3. store value 25 in the memory created in step 2
4. show the value stored in the memory created in step 2 on the monitor
5. stop your program.
with identifier to memory:
1. start your program
2. reserve some amount of memory in your RAM to store a number later with name ‘x’
3. store value 25 into ‘x’
4. show the value stored in ‘x’ on the monitor
5. stop your program.
Pseudocode (False Code)
It is an alternative way of representation of steps in the algorithm using mathematical notations to resemble steps in actual program.
pseudocode for algorithm1:
1. start
2. declare x
3. x := 25
4. write “Value of x is:”, x
5. stop
Practice Questions:-
Ex1:
Write algorithm to declare two variables and store values 10 and 15 into them, and display their sum.
Hint:
sum:=a+b
Ex2:
Write algorithm to declare two variables ‘len’ and ‘bre’ to store dimensions of rectangle. Store any desired values into those variables. calculate and display the area of the rectangle.
Hint:
area:=len*bre
Ex3:
Write algorithm to calculate area of circle for your desired radius value.
Hint:
area:=3.14*rad*rad
Ex4:
Write Algorithm to calculate average of three desired numbers
Hint:
avg:=(a+b+c)/3
Ex5:
Write Algorithm to calculate simple interest for the desired principle, rate of interest and duration
Hint:
si:=(p*n*r)/100