Learn Fundamentals of
Computer Programming
Using Python

Sponsored by - Dreamcatcher IT

Venue - Premier University Chittagong

About me

CEO, Founder of Dreamcatcher IT

 

Pythonista, Javascript Enthusiast, Thinker, Day Dreamer, And an introvert with exception!

 

  • Former Software Engineer, Team Lead, RDS Solutions
  • ICT Certified@2014 Android  Application Development Trainer

Introduction

to Computer Program

A  way to tell your computer to do things.

 

Dear Computer:
please, wash all the dishes

  • Browse web 
  • Show me a movie
  • Finish all my jobs before my boss arrives

How it works!

input

Process

output

THE IPO MODEL

data

information

Input

The act of entering Data into the computer

Process

a series of actions or steps taken in order to achieve a particular end result.

Data

Information

steps/actions

Brewing Process Illustrated

  • start
  • grain
  • milling
  • mashing
  • boiling
  • cooling
  • fermenting
  • filtering
  • conditioning
\}
}\}

Set of Steps/Actions

Algorithm

  • Finite set of steps or, processes to reach a specific outcome.
  • Unambiguous specification of how to solve a class of problems
"""
Find Largest of two Numbers

1. Take Input A, B
2. Compare A with B
    1. IF A > B Then 
    PRINT A is Largest
    2. Else PRINT B Is Largest
"""
a, b = 10, 400
largest = a if a>b else b
print(largest)

Output

Input

Process

Difference Between Algorithm & Process

 The main difference is that, the process or Procedure can halt or need not halt. But the algorithm always halt and gives an output.

Output

Any information that has been processed by a computer or similar device

Program

a series of coded software instructions to control the operation of a computer or other machine.


print("Hello World")

example - Python Script to say Hello World

What is Python?

A Giant Snake, can be weighted upto 160kg

Python is a Programming Language!!

Actually An Interpreted Programming language like Ruby or, Java

Number of Programming Languages?

According to Wikipedia, there are 276 programming languages in the world and counting...

Which One Should I choose?

Go with Python!!

Top US Universities Uses Python

Top Companies that are using Python

  • General Purpose
  • Clean Syntax
  • Easy to Learn
  • Comprehensive Standard Library
  • Excellent Documentation
  • Open Source!

So Whats the big deal about Python?

Nerds might

complain Python is slow*!!

* interpreted language remember?

But there are ways to gain incredible performance boosts!

  • Cython
  • Jython
  • Numba

most of the time it doesn't matter!

What Matters most is the Developer's Time & Effort

Lines of Code for ASF XML Serialization:

  • C++ - 1580 Lines
  • Python - 130 Lines

Application Area of
Python

Scientific Computing

  • SciPy - solves common scientific & engineering problems
  • NumPy - Matrix & Multidimensional arrays Manipulation
  • Matplotlib - Popular Plotting Libraries
  • Pandas - A handy tool for data processing
  • SymPy - Symbolic Math Libraries

Data Science

  • Machine Learning - PyTorch, Tensorflow, keras
  • Data Engineering - PySpark
  • Data Mining - Scrapy, aspyder 
  • Data Analysis - Pandas, Numpy,  
  • Data Visualization - Plotly, Matplotlib
  • Natural Language Processing - ScaPy, NLTK

Web Development

  • Frameworks- Django, Flask, Sanic, Zope, bottle
  • Task Queue - Celery
  • REST Frameworks - DRF, Flask , Falcon, Eve
  • Others - Json, BeautifulSoup, Selenium, Mechanize, asyncio, twisted, tornado

Computer Vision

  • Open CV
  • Pillow
  • Scikit-Image

Game Development

  • PyGame
  • SerpentAI
  • Blender
  • Panda3D

Embedded System

  • Raspberry Pi
  • Arduino
  • MicroPython

Desktop Application Development

Local Python Communities

I encourage you to join all of these Facebook Groups and, contribute by knowledge/resource sharing.

Break

back in 30 minutes

Hello Python!

Lets get Interactive!

Run PYTHON Run!

  • Type `python` in terminal or, just `py` if you are in windows 10 cmd
  • run python scripts:
        python your_script.py
  • run module:
        python -m some_module
  • run inline python:
        python -c "print(200)"

bonus  python -m http.server 4343

Basic Input & Output

# input takes an optional argument string
name = input("Enter your name")
print("Your name is", name)
# the name variable will be a string
print(type(name))
a, b, c =  1, 2, 3
print(a,b,c, sep=" * ", end="")

this just a drop of the ocean! there are tons of ways to take inputs & outputs in Python. Explore them to know more about them!

Everything in Python is an Object!

Variables, Data Type, Conditionals

4  Data Types

  • int - Integer Numbers
  • float - Floating point numbers i.e decimals
  • str - string data type
  • bool - boolean data type (subclass of int)

Type Conversion

num = 10000
converted_string = str(num)
converted_num = int(converted_string)

  • int() - convert to integer with base
  • float() - convert to float
  • str() - convert to string

Variables & Data Types

Conditionals

number = 15

guess = int(input())

if number == guess:

    print("Great! Your guess is right")

elif number < guess:

    print("Your guess is greater than the number")

else:

    print("Your guess is smaller than the number")
n = 100

age = 35.5

name = 'Tom'


type(n)
output: <class 'int'>

type(age)
output: <class 'float'>

type(name)
output: <class 'str'>

Conditionals

# python supports multiple assignments
a, b, c = 1, 2, 3
# swap a with b
a, b = b, a
if a<b<c:
    print(c, "is largest")
# shortcut
a = b if b>c else c

Some simple string operations using built ins

my_string = "Hello World"
print(my_string.lower())
print(my_string.upper())
print(my_string.title())
print(my_string.isalpha())
print(my_string.isnumeric())

Basic python data structure

lists: l = [2, 5, 'a', 'google']

tuples: t = (3, 7, "a")

dictionary: d = {"name": "Bob", "age": 35}

 

list, tuple, dict

#list definition
my_list = [1,2,3,4,5]
# access last element
print(my_list[-1])
# reverse a list
print(my_list[::-1]
# add an element
my_list.append(494)
# insert element using index
my_list.insert(4, 2094)

# dictionary
d = dict()
d = {
    "key": "value",
     2: "another value",
    "string"; "this is a string",
}
# tuple
tuple = (1, 2, 3, 4, 5)
# Tuples are immutable
# can't insert element or remove from it

Loops, Iterators, Generators

Loops

Iterators

Iterators are in python simply an object that can be iterated upon. 

 

for number in range(1,10):
    print(number, end=" ")

output: 1 2 3 4 5 6 7 8 9
i = 0
while(i < 10):
    print(i, end=" ")
    i = i + 1
num_list = [1, 2, 3, 4]

num_iter = iter(num_list)
print(next(num_iter))
print(next(num_iter))

For Loop

while Loop

Generators

a generator is a function that returns an object (iterator) which we can iterate over (one value at a time).

Example of Generators

  • map()
  • range()

Use Case of Generator

def first_n(n):
    """
    returns a list of numbers from 0 to n
    
    >>>first_n(5)
    >>>[0,1,2,3,4] 
    """
    num, numbers = 0, []
    while num < n:
        numbers.append(num)
        num += 1
    return numbers

print(sum(first_n(1000000)))

Replace it with a shiny Generator!

# a generator that yields items instead of returning a list
def first_n(n):
    num = 0
    while num < n:
        yield num
        num += 1

List Comprehension

Concise way of creating list

 

[i for i in range(1,20) if not i%2]

output: [2, 4, 6, 8, 10, 12, 14, 16, 18]

Power of List Comprehension!

# Generate primes within 1-100
primes = [ i for i in range(2, 100) if 0 not in [i%j for j in range(2, i)] ]

Function

  • organized block of code
  • reusable
  • do one thing, do it well
def addition(num1, num2):
    """
        This function takes two values of
        num1 and num2 as parameter
        and will return their sum
    """
    result = num1 + num2
    return result

Basic Approach Of Problem Solving

Step 1: Define the Problem

Step 2: Identify the key elements

Step 3: Plan the steps and, consider the difficulty or complexity of each step

Step 4: Find alternatives of the complex parts

Step 5: Start with the naive/minimal implementation

Step 6: Keep an eye on the Edges!

Step 7: Once solved try to improve the solution as much as possible

Questions?

Solve these easy problems within next week!

You must start solving from the 'Say Hello World!' problem and, solve at least till the minion game problem if you need any help, post it here

Rather Simple Tasks!

Thank you!

All the images and logos in this slide are collected from Internet and, used only for educational purpose. 

Learn Fundamentals Of Computer Programming Using Python Part 1

By Wasi Mohammed Abdullah

Learn Fundamentals Of Computer Programming Using Python Part 1

Aimed for absolute beginners who have a little or, no knowledge of computer programming. It will provide the grasp of basic programming concepts with solid understanding of fundamentals.

  • 1,466