# Learn Fundamentals of Computer Programming Using Python

Sponsored by - Dreamcatcher IT

Venue - Premier University Chittagong

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

## 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

# Number of Programming Languages?

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

# 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!

# 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

• Open CV
• Pillow
• Scikit-Image

• PyGame
• SerpentAI
• Blender
• Panda3D

• Raspberry Pi
• Arduino
• MicroPython

## 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!

# 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

## 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

## 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).

• 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

# 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.

• 477