Programming
Overview

How lisa understands your recipe
- lisa remembers values when you give some name to it
Remember 1000 as amount
or
amount = 1000
- lisa executes the instructions in a step by step order
1. instrcution 1
2. instruction 2
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
- we can store the result of operation as shown below
gst = (amount * 18 / 100)
Calculate (amount * 18 / 100) and store into gst
Problem 1:
- Statement: I want lisa to calculate if the year is leap or not
- Simple version: if the year is divisible by 4
1. Remember 1996 as year
2. calculate year % 4 and store in result
3. if result == 0 say leap year
- Actual version
- if number is divisible 4 but not by 100 its a leap year
- if the number is divisible by 4 and also by 100 it should be divisible by 400 to be a leap year
- Solution
1. Remember 1900 as year
2. is_divisible_by_4 = year % 4
3. is_divisible_by_100 = year % 100
4. is_divisible_by_400 = year % 400
5. if is_divisible_by_4 == 0
5.1 if is_divisible_by_100 == 0
5.1.1 if is_divisible_by_400 == 0 then say leap year
5.2 else is_divisible_by_100 != 0 then say leap year
Problem 2:
-
Make lisa tell if the number is pallendrome or not
-
lisa knowledge
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
1. number = 153
2. actual_number = number
3. reverse_number = 0
4. remainder = number % 10
5. number = number / 10
6. reverse_number = (reverse_number * 10) + remainder
7. if number != 0 goto step 4
8 if actual_number == reverse_number say pallendrome
9. else say not a pallendrome
Problem 3:
1,2,3,5,8,13,21,34,55,89......
- Make lisa say all the fibonnaci series numbers below 50
- lisa knowledge
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
1. first_number = 1
2. second_number = 2
3. say first_number
4. say second_number
5. result = first_number + second_number
6. say result
7. first_number = second_number
8. second_number = result
9. if result < 50 then go to step 5
Programming Concept
- Every process has its own CPU cycles and memory which is private to it
- To reuse functionality
- use packages or libraries
Like this:
Like Loading...