1. number = 43
2. remainder = number % 2
3. if remainder == 0 say even
4. else say odd
Generally once you convert the solution into code, we need to test by supplying multiple values. This approach is referred as unit testing
For figuring out values we go with boundary conditions
Reasoning: Developer finding defects in the code which he/she writes is most effective in terms of time and cost rather than QA finding it and in worse case customer finding it.
Problem 5
Make lisa tell if the number passed is prime or not
1. number = 2
2. if number < 2 say not prime and exit
3. if number == 2 say prime and exit
4. start = 2
5. remainder = number % start
6. if remainder == 0 say not prime and exit
7. start = start + 1
8. if start < number/2 go to step 5
9. say prime
Problem 6
Lisa has a book/dictionary where the entries are like which represent gst
key value
clothing 5
gold 5
school 0
profesional education 18
..
...
..
..
We need to pass item category and price to lisa she should tell the actual price including gst
Solution
1. item = 'laptop'
2. item_category = 'electronics'
3. item_price = 100000
4. findout the percentage from gst_dictionary and store it in gst
gst = gst_dictionary(item_category)
5. total_price = total_price + total_price * gst/100
6. say total_price
Conditional’s
Example
Income Tax Slabs (Rs) Income Tax Rate (%)
From 0 to 3,00,000 0
From 3,00,001 to 6,00,000 5
From 6,00,001 to 9,00,000 10
From 9,00,001 to 12,00,000 15
From 12,00,001 to 15,00,000 20
From 15,00,000 to 100,00,000 30
Above 100,00,000 35
solution
salary = 200000
if salary > 0 and salary <= 300000
tax_rate = 0
else if salary > 300000 and salary <= 600000
tax_rate = 5
else if salary > 600000 and salary <= 900000
tax_rate = 10
else if salary > 900000 and salary <= 1200000
tax_rate = 15
else if salary > 1200000 and salary <= 1500000
tax_rate = 20
else if salary > 1500000 and salary <= 1000000
tax_rate = 30
else if salary > 10000000
tax_rate = 35
say tax_rate
tax = salary * tax_rate / 100
net = salary - tax
loops
Generally based on some conditions we might need to execute certain line(s) multiple times, this is where we use loops
number = 7
if number < 2
say not prime
exit
end if
if number == 2
say prime
exit
end if
start = 2
until start < number
remainder = number % start
if remainder == 0
say not prime
exit
start = start + 1
end until
say prime
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
and
or
solution
max = 1000
result = 0
start = 1
until start < max
if start%3 == 0 or start%5 == 0
result = result + start
end if
start = start + 1
end until
say result
first = 1
second = 2
result = 2
max = 4000000
until first + second < max
third = first + second
if third % 2 == 0
result = result + third
end if
first = second
second = third
end until
print result