Python Classroom notes 12/Dec/2024

Programming

Problem 4

  • Make lisa tell if the number is even or odd
  • lisa knowledge
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
  • Solution:
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
    Preview
  • 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
  • lisa knowledge
* multiply
+ add
/ division
% modulus or remainder
- subtraction
== equals
!= not equals
< <= >= >
= assignment
  • Solution
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

Resources

Make lisa solve Project euler problem 1

* 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

Make lisa solve Project euler problem 2

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

Conceptual

  • Inter Process Communication (IPC) was introduced to allow one process communicating with same process on the same host
  • But running everything on same host was expired very soon as Client Server Compuational model has become of extreme importance
  • To make this communication possible we have to deal with networking i.e where tcp or udp or http or https come into play
  • To solve this problem, the popular technologies
    • Remoting
    • Web Services was introduced by microsoft (WSDL)
    • to make it simple and scalable REST APIs or HTTP APIs were introduced

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube