Sponsored by - Dreamcatcher IT
Venue - Premier University Chittagong
CEO, Founder of Dreamcatcher IT
Pythonista, Javascript Enthusiast, Thinker, Day Dreamer, And an introvert with exception!
A way to tell your computer to do things.
Dear Computer:
please, wash all the dishes
input
Process
output
THE IPO MODEL
data
information
The act of entering Data into the computer
a series of actions or steps taken in order to achieve a particular end result.
Data
Information
steps/actions
Set of Steps/Actions
"""
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
The main difference is that, the process or Procedure can halt or need not halt. But the algorithm always halt and gives an output.
Any information that has been processed by a computer or similar device
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
A Giant Snake, can be weighted upto 160kg
According to Wikipedia, there are 276 programming languages in the world and counting...
* interpreted language remember?
most of the time it doesn't matter!
Lines of Code for ASF XML Serialization:
I encourage you to join all of these Facebook Groups and, contribute by knowledge/resource sharing.
back in 30 minutes
Lets get Interactive!
bonus python -m http.server 4343
# 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!
num = 10000
converted_string = str(num)
converted_num = int(converted_string)
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'>
# 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
my_string = "Hello World"
print(my_string.lower())
print(my_string.upper())
print(my_string.title())
print(my_string.isalpha())
print(my_string.isnumeric())
lists: l = [2, 5, 'a', 'google']
tuples: t = (3, 7, "a")
dictionary: d = {"name": "Bob", "age": 35}
#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
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
a generator is a function that returns an object (iterator) which we can iterate over (one value at a time).
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)))
# a generator that yields items instead of returning a list
def first_n(n):
num = 0
while num < n:
yield num
num += 1
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]
# 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)] ]
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
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
All the images and logos in this slide are collected from Internet and, used only for educational purpose.