SlideShare a Scribd company logo
Intro to Python for
Non-Programmers
Ahmad Alhour / Team Lead, TrustYou
23 April, 2019
Overview
● A very basic intro to programming
● Intended for people who have no clue about it
● Mainly, to give you a taste of what it is about
● Hopefully, it’ll put you on the right track to study
on your own
3aalhour.com
Hello!
I am Ahmad
I have been doing programming as a
hobby since I was a kid, and
professionally since 2008. I also have
a B.Sc. degree in Computer Science.
At TrustYou, I lead several projects, all
powered by Python!
4
15 mins
Intro and Setting
Expectations
30 mins
What is Programming?
10 mins
Intro to REPL.it
45 mins
Numbers, Variables
and Strings
30 mins
Functions (Part 1)
Plan Until Lunch
15 mins
Recap and
Review
45 mins
Conditionals
45 mins
While Loops
and Collections
45 mins
For Loops and
Functions (Part 2)
30 mins
Wrapping Up
Plan After Lunch
1.
What Are Your
Expectations?
7aalhour.com
““Blessed is he who expects nothing,
for he shall never be disappointed.”
― Alexander Pope
8aalhour.com
Group Exercise:
Let’s Set Expectations Together
● Learn the basics of Programming
● Learn the basics of Python
● There will be no installation
9aalhour.com
2.
What is Programming?
10aalhour.com
12
Programming 101
● Is a way of telling the computer how to
do certain things by giving it a set of
instructions
● These instructions are called Programs
● Everything that a computer does, is
done using a computer program
aalhour.com
Example Programs
13aalhour.com
3.
What is a Programmer?
14aalhour.com
15
What is a Programmer?
“A programmer is an Earthling who can
turn big amounts of caffeine and pizza
into code!”
― Anonymous
aalhour.com
17
Seriously, what is a programmer?
● A person who writes instructions is a
computer programmer
● These instructions come in different
languages
● These languages are called computer
languages
aalhour.com
4.
What is a Programming
Language?
18aalhour.com
19
What is a Programming
Language?
● A programming language is a type of
written language that tells computers
what to do
● They are used to make all the
computer programs
● A P.L. is like a set of instructions that
the computer follows to do something
aalhour.com
20
Machine Language
● The computer’s native language
● The set of instructions have to be
coded in 1s and 0s in order for the
computer to follow them
● Writing programs in binary (1s and 0s)
is tedious
● Lowest level language
aalhour.com
21
High-level Languages
● Programming languages that are
closer to English than Machine code
● Human-readable
● Expresses more by writing less
aalhour.com
5.
Example Programs
22aalhour.com
23
Displaying “Hello, World!”
in Machine Code
0110100001100101011011
0001101100011011110010
0000011101110110111101
1100100110110001100100
24
Displaying “Hello, World!”
in Assembly
global _main
extern _GetStdHandle@4
extern _WriteFile@20
extern _ExitProcess@4
section .text
_main:
; DWORD bytes;
mov ebp, esp
sub esp, 4
; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE)
push -11
call _GetStdHandle@4
mov ebx, eax
; WriteFile( hstdOut, message, length(message), &bytes,
0);
push 0
lea eax, [ebp-4]
push eax
push (message_end - message)
push message
push ebx
call _WriteFile@20
; ExitProcess(0)
push 0
call _ExitProcess@4
; never here
hlt
message:
db 'Hello, World', 10
message_end:
25
#include <stdio.h>
int main(void)
{
printf("Hello, World!n");
return 0;
}
Displaying “Hello, World!”
in C
26
print(“Hello, World!”)
Displaying “Hello, World!”
in Python
6.
Enter: Python!
27aalhour.com
29
The Python Programming
Language
● High-level programming language
● Named after BBC’s
"Monty Python’s Flying Circus" show
● One of the most adopted languages
world-wide
● Most TY products are powered by it
aalhour.com
30
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for each_number in numbers:
print(each_number)
Example Python Program:
Counting to 10
Let’s take a break!
7.
Let’s REPL.IT
32aalhour.com
33
Demo Time!
● General walk through REPL.IT
aalhour.com
8.
Hello, World!
Your First Python Program
34aalhour.com
35
Numbers in Python
● Create a new repl on REPL.IT
● Type in the main.py tab:
print(“hello, world!”)
● Click on run >!
aalhour.com
9.
Numbers
The Art of Calculating Stuff
36aalhour.com
37
Numbers in Python
● One of value types
● Demo:
○ Numbers in interactive mode
○ Basic arithmetic
aalhour.com
38
Evaluation Order of Operations
● First, “*” and “/” are evaluated
● Then, “-” and “+” are evaluated
● All operations are evaluated
left-to-right
aalhour.com
39
Guess the result of the following:
● 9 * 9 - 9 * 10 / 15
● 1 + 1 + 1 * 2 + 6 / 2
● 10 + 1 * 2 - 4 / 20
● 50 - 5 - 5 - 10 / 2
● 1 + 2 - 5 * 3 - 7 + 4 * 9 / 12
aalhour.com
40
Grouping Calculations with
Parentheses
● Used for separating calculations into
distinct groups
● For example:
○ (10 * 2) + (5 - 3) / (4 + 2)
○ → 20 + 2 / 6
○ → 20 + 0.333
○ → 20.333
aalhour.com
41
Evaluation Order of Operations:
Revisited!
● First, what is in “(” and “)” is evaluated
● Then, “*” and “/” are evaluated
● Then, “-” and “+” are evaluated
● All operations are evaluated
left-to-right
aalhour.com
42
Guess the result of the following:
● 9 * (9 - 9) * 10 / 15
● (1 + 1 + 1) * (2 + 6) / 2
● 10 + 1 * (2 - 4) / 20
● 50 - 5 - (5 - 10) / 2
● (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12
aalhour.com
10.
Variables
The Art of Naming Stuff
43aalhour.com
44
Variables in Python
● Used to give names to values
● You give names to stuff to refer to
them later on in your program
● You give names to stuff using the “=”
symbol, known as “assignment
operator”
● Variable names must begin with a
letter
aalhour.com
45
● Implement one plus one operations
using variables
Demo Time
aalhour.com
46
Example usage:
● Calculate the average population for
Earth in 2015
● Give it a name
● Everytime you want to refer to it you
just use the name rather than to
recalculate it again
Variables in Python
aalhour.com
47
Break the calculation down using
variables:
● (10 * 2) + (5 - 3) / (4 + 2)
● X + Y / Z
● Store result in “result” name
Demo Time
aalhour.com
48
Break the following calculations down
into sub-calculations and store them into
variables:
● 9 * (9 - 9) * 10 / 15
● (1 + 1 + 1) * (2 + 6) / 2
● 10 + 1 * (2 - 4) / 20
● 50 - 5 - (5 - 10) / 2
● (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12
Exercise
aalhour.com
11.
Strings
The Art of Texting Stuff
49aalhour.com
50
● Used to represent text in Python
● Examples:
○ “Hello, World!”
○ “My name is Ahmad.”
○ “Bier und Brezel.”
● Any text in between “” is a string in
Python
Strings in Python
aalhour.com
51
● Type in the following strings in the
interactive shell:
○ “Hello, World!”
○ “My name is Ahmad.”
○ “Bier und Brezel.”
● Use all of the above with print
● Store all of the above in variables and
then print them
Demo Time
aalhour.com
52
Print the following poem:
Doubt thou the stars are fire;
Doubt that the sun doth move;
Doubt truth to be a liar;
But never doubt I love.
― William Shakespeare, Hamlet
Exercise
aalhour.com
Let’s take a break!
54
12.
Functions
The Art of Naming
Computations
aalhour.com
55
● Just like how variables give name to
values, functions give name to
calculations/instructions
● It is easier to refer to a group of
instructions with a name than write
them all over again
● You need three main words to define
functions: “def”, “<name>” and “return”
Functions in Python
aalhour.com
56
● You know functions already!
● Print is a Python function that takes
whatever value you’d like and prints it
on the screen
● Print can take several values
separated by commas, e.g.:
○ print(“My name is:”, “Slim Shady”)
○ print(“One plus one is:”, 2)
Functions in Python
aalhour.com
57
● Define a new function
● Print William Shakespeare’s poem
● repl.it/@aalhour/WilliamShakespeare
Demo Time
aalhour.com
58
● Define a new function
● Code the one plus one example in
variables
● Return the result
Demo Time
aalhour.com
59
● Define a function to calculate each of
the following, with variables, and
return the result:
○ 9 * (9 - 9) * 10 / 15
○ (1 + 1 + 1) * (2 + 6) / 2
○ 10 + 1 * (2 - 4) / 20
○ 50 - 5 - (5 - 10) / 2
○ (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12
Exercise
aalhour.com
60
● Functions can take values as
arguments!
● Useful for doing tasks with user input,
for example:
○ Given 5 numbers, return the avg.
○ Given weight and height of a
person, calculate their BMI.
Functions in Python
aalhour.com
61
● Define a new function for printing
different values
● Define a new function for calculating
BMI given height and weight
● repl.it/@aalhour/FuncsWithVars
Demo Time
aalhour.com
62
● Define a function that accepts two
arguments and returns the result of
their addition
● Define a function that takes five
arguments and returns the average
Exercise
aalhour.com
Lunch Break
See you in an hour!
15 mins
Recap and
Review
45 mins
Conditionals
45 mins
While Loops
and Collections
45 mins
For Loops and
Functions (again!)
30 mins
Wrapping Up
Plan After Lunch
13.
Recap
What Have We Learned So
Far?
65aalhour.com
66
● Numbers: 1, 2, 3
● Order of operations: (, ), *, /, +, -
● Strings: “Hi!”
● Variables: x = 1
● Functions:
def greet():
print(“Hello, world!”)
Recap
aalhour.com
14.
Conditionals
The Art of Comparing Stuff
67aalhour.com
68
● They are the Yes/No questions of
programming
● The answer is either a True or a False
● These values are called Booleans
● Conditionals compare values together
● Using simple operators such as:
○ >, <, >=, <= and ==
Conditionals
aalhour.com
69
Compare several numbers together and
check the results:
● 1 < 10
● 1 <= 10
● 5 > 2
● 5 >= 2
● 1 == 1
● 0 <= 0
Demo Time
aalhour.com
70
Evaluate the following in your mind and
then on REPL.IT:
● 1 + 1 + 1 + 1 + 1 > 4
● 2 * 2 < 5 / 3
● 5 * 3 >= 15
● 10 / 2 == 5
● (25 * 3) - 100 / 2 < (25 * 2) + 1
Exercise
aalhour.com
71
● First, what is in “(” and “)” is evaluated
● Then, “*” and “/” are evaluated
● Then, “-” and “+” are evaluated
● Lastly, comparisons are evaluated
○ “>”, “>=”, “<”, “<=”, “==”
● Operations get evaluated left-to-right
Evaluation Order of Operations:
Expanded
aalhour.com
72
● A Python statement for making
decisions based on a condition
● In a nutshell: if this, then that
● For example:
If your age is greater than 18,
then you are allowed to enter the bar
The If Statement
aalhour.com
73
● If old enough to enter bar, print
“proceed to bar!”.
● If not old enough to enter bar, print
“too young still!”
Demo Time
aalhour.com
74
Teenager Exercise 01:
Define an “age” variable and insert your
age. Write an if statement to display
“teenager” if age is less than 21
Exercises
aalhour.com
75
Exercises
Positive Number 01:
Define a “number” variable and insert a
random value. Write an if statement to
display “positive” if the number is greater
than 0
aalhour.com
76
● Expanded If-Statement for handling
cases that don’t match the condition.
● In a nutshell: if this, then that;
otherwise, something else
● For example:
○ If your age is greater than 18, then
you are allowed to enter the bar;
otherwise, you are asked to leave
The If-Else Statement
aalhour.com
77
Translate the following into Python:
If old enough to enter bar
then print “proceed to bar!”
else print “please, leave!”
Demo Time
aalhour.com
78
● Teenager Exercise 02:
Expand the code and add an else
block which prints “adult” if the
teenager check is not met
● Positive Number 02:
Expand the code and add an else
block which prints “negative” if the
positive check is not met
Exercises
aalhour.com
79
● Teenager Exercise 03:
Wrap the exercise’s code in a function
that accepts an “age” argument and
returns nothing.
● Positive Number 03:
Wrap the exercise’s code in a function
that accepts a “number” argument and
returns nothing.
Exercises
aalhour.com
Let’s take a break!
15.
While Loops
The Art of Repeating Stuff
81aalhour.com
82
● Loops are good for repeating
instructions for a number of times
● They’re good because we don’t have
to duplicate code, but we just tell the
program to keep repeating stuff
● Loops repeat stuff according to a
condition as well
While Loops
aalhour.com
83
● Example:
○ While my BMI is above 100, keep
working out!
○ While my coffee is not empty, keep
writing code!
● You need two words to loop stuff:
○ “while” and “break”
○ Break is used to stop looping or
else you will loop forever!
While Loops
aalhour.com
84
while True:
print(1) # Prints 1 forever
while 1 == 1:
print(1) # Prints 1 forever
while 5 > 2:
print(1) # Prints 1 forever
Code Examples
aalhour.com
85
# Prints 1 once, then stops
while True:
print(1)
break
# Prints 1 once, then stops
while 1 == 1:
print(1)
break
Code Examples
aalhour.com
86
● Print “Hello, World!” forever!
● Print your own name forever!
● Calculate the following formula and
print the result forever:
○ 10 * 312 / 57 + 23 * 5 + 823 / 74
Play Time
aalhour.com
87
● To avoid running forever, we need to
maintain a counter and a limit
● Counters are variables that keep track
of how many times a loop ran
● Limits allow us to break out of the loop
once the loop runs for a max. number
of times
Counters and Limits
aalhour.com
88
counter = 1
while counter < 10:
print(counter)
counter = counter + 1
Code Example
aalhour.com
89
● Add a counter number and increment it
inside the loop. Print the counter to
show that its value changes.
● Add a limit check before the work with
a break.
Demo Time
aalhour.com
90
● Print numbers from 0 until 1 million
● Teenager Exercise 04:
Define age variable and assign it to 1.
Run the loop with the teenager check.
The loop should print the age and then
increment it until the age is no longer
teeanger, after which the loop should
terminate
Exercises
aalhour.com
91
● You can ask for the user’s input using
the built-in “input” function
● For example:
input(“Enter a number:”)
● Useful for asking the user for data.
User Input
aalhour.com
92
● Ask the user for their name and then
print it out.
● Ask the user for their age and print it
out with the statement: “Your age is:”
Demo Time
aalhour.com
93
Teenager Exercise 05:
Ask the user for their age. Run the loop
with the teenager check on the user
input. The loop should print “You are still
a teenager” alongside the age and then
increment it until the age is no longer
teeanger, after which the loop should
terminate.
Exercises
aalhour.com
94
Teenager Exercise 06:
Wrap the Teenager Exercise #05 with a
function that asks the user for their age
and then prints out the message: “You
are still a teenager:” alongside their age.
Increments the age number until the
loop no longer runs.
Exercises
aalhour.com
Let’s take a break!
16.
Collections
The Art of Grouping Stuff
96aalhour.com
97
● Collections are a way of keeping items
together, e.g.: bags!
● We will take a look at lists in Python
● Lists are good for memorizing the
order in which we keep things too
Collections
aalhour.com
98
A list of numbers:
[1, 2, 3, 4, 5]
A list of strings:
[“Alice”, “Bob”, “Claire”]
A mixed list of things:
[123, “Ahmad”, message]
Examples of Collections
aalhour.com
99
Anything in between “[” and “]” is
considered a list
A list can contain anything in Python:
● Numbers
● Strings
● Variables
● Other lists
How can I create a collection?
aalhour.com
100
● Create a list of the English alphabet
● Create a list that contains your:
○ first name
○ last name
○ your lucky number
○ your current address
● Print the above lists using the print()
function
Exercises
aalhour.com
101
● Ranges in Python are useful functions
for generating collections of numbers
● More like a shortcut
● Easy to use
● Example:
○ range(1, 10): generates a collection
of all numbers from 1 until 9 (stops
at 10 but doesn’t include it)
Ranges
aalhour.com
102
● range() takes three arguments:
○ Start: number to start with
○ End: number to stop at
○ Step: increment size
● Examples:
○ range(0, 5, 1) → [0,1,2,3,4,5]
○ range(0, 6, 2) → [0, 2, 4]
○ range(0, 6, 3) → [0, 3]
Ranges: In Detail
aalhour.com
103
● start = 0 by default, unless specified
● step = 1 by default, unless specified
● end is mandatory and must be always
specified
● Examples:
○ range(6) → [0,1,2,3,4,5]
■ Same as: range(0, 6, 1)
Ranges: Default Behavior
aalhour.com
104
● Generate a list of all odd numbers
greater than 0 and less than 1000
● Generate a list of all even numbers
greater than 29 and less than 250
● Generate a list of all numbers less
than -1 and greater than -132
● Generate a list of all even numbers
less than -250 and greater than -277
Exercises
aalhour.com
Let’s take a break!
17.
For Loops
The Art of Iterating Over
Collections
106aalhour.com
107
● For loops are another way to apply the
same computation more than once
according to a check in your program
● Similar to While Loops but easier to
maintain
○ No need for a counter
○ No need for a beaking check
For Loops
aalhour.com
108
For loops need a collection in order to…
well, loop! :P
Example: for every item in shopping cart,
print it out on the screen:
for item in [“Shoes”, “Tablet”]:
print(item)
For Loops
aalhour.com
109
for number in [1, 2, 3, 4, 5]:
print(number)
for number in range(6):
print(number)
for person in [“AA”, “AM”, “DW”, “DV”]:
print(person)
For Loops: Examples
aalhour.com
110
● Syntax:
○ for <variable name> in <collection>:
■ List of commands
● The variable name can be whatever
you want
● The collection can have whatever you
want but it must be a collection, not
anything else
How do I make a for loop?
aalhour.com
111
1. For every item in the collection:
a. Assign the item to the variable
name that the programmer wrote
b. Enter the block
c. Execute all commands
d. Go to 1 and grab the next the item
2. If the collection is empty or has no
more items to see, then exit the block
How do for loops work?
aalhour.com
112
for number in [1, 2, 3, 4, 5]:
print(number)
Loop execution log:
number = 1 → print(1)
number = 2 → print(2)
number = 3 → print(3)
number = 4 → print(4)
number = 5 → print(5)
Demo
aalhour.com
113
● Using range() and a for loop:
○ Print your name 25 times
○ Print “Hello, World!” 10 times
Play time!
aalhour.com
114
Teenager Exercise 01: Reloaded
Ask the user for their age. Check if the
user is a teenager. Run a for loop over a
range of ages until an age value that is
not a teenage number anymore. Run a
for loop and display the “you’re a
teenager” message according to the list
of ages (range)
Exercises
aalhour.com
115
Teenager Exercise 02: Reloaded
Wrap your solution for the “Teenager
Exercise 01: Reloaded” exercise with a
function that asks the user for their age
and then prints out the message:
“You are still a teenager:” alongside their
age.
Exercises
aalhour.com
Let’s take a break!
18.
Functions: Reloaded
The Art of Naming
Computations
117aalhour.com
118
Let’s solve the FizzBuzz challenge!
Functions: Reloaded
aalhour.com
17.
Wrapping Up
119aalhour.com
120
● Numbers: 1, 2, 3
● Order of operations: (, ), *, /, +, -, <, >, >=, <=, ==
● Strings: “Hi!”
● Variables: x = 1
● Functions:
def greet(person):
print(“Hello, ”, person)
● Conditionals: 1 >= 10
What You’ve Learned So Far
aalhour.com
121
● While Loops:
while True:
greet(“Ahmad”)
● Lists:
[1, 2, 3, “Alice”, “Bob”]
● Ranges:
range(10) → [1, 2, 3, …, 9]
● For Loops:
for number in range(10):
print(number)
What You’ve Learned So Far
aalhour.com
18.
Resources for Further
Study
122aalhour.com
123
Online Courses
● Intro to Python - by Udacity
○ https://bit.ly/2N45h6F
○ 5 weeks long. Completely FREE.
● Intro to Python: Absolute Beginner - by edX
○ https://bit.ly/2NJg2MW
○ 5 weeks. Completely FREE.
● Python for Everybody - by Coursera
○ https://bit.ly/1KSzsbb
○ 7 weeks long. Only first seven days are free.
Resources for Further Study
aalhour.com
124
Resources for Further Study
Interactive Learning
● Codecademy - Learn by Coding
○ https://www.codecademy.com
○ Completely Free.
Books
● Think Python, 2nd edition
○ http://greenteapress.com/thinkpython2
○ Completely Free Online.
aalhour.com
Thanks!
Any questions?
125
Find me at:
aalhour.com
github.com/aalhour
twitter.com/ahmad_alhour
aalhour.com

More Related Content

What's hot

Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
AnirudhaGaikwad4
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Python basic
Python basicPython basic
Python basic
SOHIL SUNDARAM
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Edureka!
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
St. Petersburg College
 
Python programming
Python programmingPython programming
Python programming
Prof. Dr. K. Adisesha
 
Basics of python
Basics of pythonBasics of python
Basics of python
SurjeetSinghSurjeetS
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
Samir Mohanty
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
Mayank Sharma
 
Basics of python
Basics of pythonBasics of python
Basics of python
Jatin Kochhar
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
rfojdar
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
Collaboration Technologies
 
Python
PythonPython
Python
SHIVAM VERMA
 
Python
PythonPython

What's hot (20)

Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python basic
Python basicPython basic
Python basic
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Python programming
Python programmingPython programming
Python programming
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Python programming
Python  programmingPython  programming
Python programming
 
Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Python
PythonPython
Python
 
Python
PythonPython
Python
 

Similar to Intro to Python for Non-Programmers

Logika dan Algoritma pemrograman
Logika dan Algoritma pemrogramanLogika dan Algoritma pemrograman
Logika dan Algoritma pemrograman
Arif Huda
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Osama Ghandour Geris
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
01 Introduction to Python
01 Introduction to Python01 Introduction to Python
01 Introduction to Python
Ebad ullah Qureshi
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
Bhalaji Nagarajan
 
Python for web security - beginner
Python for web security - beginnerPython for web security - beginner
Python for web security - beginner
Sanjeev Kumar Jaiswal
 
04 Functional Programming in Python
04 Functional Programming in Python04 Functional Programming in Python
04 Functional Programming in Python
Ebad ullah Qureshi
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
lailoesakhan
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
GaneshRaghu4
 
Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
Osama Ghandour Geris
 
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
Dylan-Wu
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
Ebad ullah Qureshi
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
Learnpython 151027174258-lva1-app6892
Learnpython 151027174258-lva1-app6892Learnpython 151027174258-lva1-app6892
Learnpython 151027174258-lva1-app6892
Neeraj Yadav
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Dr.YNM
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
Osama Ghandour Geris
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 

Similar to Intro to Python for Non-Programmers (20)

Logika dan Algoritma pemrograman
Logika dan Algoritma pemrogramanLogika dan Algoritma pemrograman
Logika dan Algoritma pemrograman
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandour
 
01 Introduction to Python
01 Introduction to Python01 Introduction to Python
01 Introduction to Python
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
Python for web security - beginner
Python for web security - beginnerPython for web security - beginner
Python for web security - beginner
 
04 Functional Programming in Python
04 Functional Programming in Python04 Functional Programming in Python
04 Functional Programming in Python
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
Lecture1
Lecture1Lecture1
Lecture1
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
 
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Learnpython 151027174258-lva1-app6892
Learnpython 151027174258-lva1-app6892Learnpython 151027174258-lva1-app6892
Learnpython 151027174258-lva1-app6892
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 

Recently uploaded

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 

Recently uploaded (20)

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 

Intro to Python for Non-Programmers

  • 1. Intro to Python for Non-Programmers Ahmad Alhour / Team Lead, TrustYou 23 April, 2019
  • 2.
  • 3. Overview ● A very basic intro to programming ● Intended for people who have no clue about it ● Mainly, to give you a taste of what it is about ● Hopefully, it’ll put you on the right track to study on your own 3aalhour.com
  • 4. Hello! I am Ahmad I have been doing programming as a hobby since I was a kid, and professionally since 2008. I also have a B.Sc. degree in Computer Science. At TrustYou, I lead several projects, all powered by Python! 4
  • 5. 15 mins Intro and Setting Expectations 30 mins What is Programming? 10 mins Intro to REPL.it 45 mins Numbers, Variables and Strings 30 mins Functions (Part 1) Plan Until Lunch
  • 6. 15 mins Recap and Review 45 mins Conditionals 45 mins While Loops and Collections 45 mins For Loops and Functions (Part 2) 30 mins Wrapping Up Plan After Lunch
  • 8. ““Blessed is he who expects nothing, for he shall never be disappointed.” ― Alexander Pope 8aalhour.com
  • 9. Group Exercise: Let’s Set Expectations Together ● Learn the basics of Programming ● Learn the basics of Python ● There will be no installation 9aalhour.com
  • 11.
  • 12. 12 Programming 101 ● Is a way of telling the computer how to do certain things by giving it a set of instructions ● These instructions are called Programs ● Everything that a computer does, is done using a computer program aalhour.com
  • 14. 3. What is a Programmer? 14aalhour.com
  • 15. 15 What is a Programmer? “A programmer is an Earthling who can turn big amounts of caffeine and pizza into code!” ― Anonymous aalhour.com
  • 16.
  • 17. 17 Seriously, what is a programmer? ● A person who writes instructions is a computer programmer ● These instructions come in different languages ● These languages are called computer languages aalhour.com
  • 18. 4. What is a Programming Language? 18aalhour.com
  • 19. 19 What is a Programming Language? ● A programming language is a type of written language that tells computers what to do ● They are used to make all the computer programs ● A P.L. is like a set of instructions that the computer follows to do something aalhour.com
  • 20. 20 Machine Language ● The computer’s native language ● The set of instructions have to be coded in 1s and 0s in order for the computer to follow them ● Writing programs in binary (1s and 0s) is tedious ● Lowest level language aalhour.com
  • 21. 21 High-level Languages ● Programming languages that are closer to English than Machine code ● Human-readable ● Expresses more by writing less aalhour.com
  • 23. 23 Displaying “Hello, World!” in Machine Code 0110100001100101011011 0001101100011011110010 0000011101110110111101 1100100110110001100100
  • 24. 24 Displaying “Hello, World!” in Assembly global _main extern _GetStdHandle@4 extern _WriteFile@20 extern _ExitProcess@4 section .text _main: ; DWORD bytes; mov ebp, esp sub esp, 4 ; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE) push -11 call _GetStdHandle@4 mov ebx, eax ; WriteFile( hstdOut, message, length(message), &bytes, 0); push 0 lea eax, [ebp-4] push eax push (message_end - message) push message push ebx call _WriteFile@20 ; ExitProcess(0) push 0 call _ExitProcess@4 ; never here hlt message: db 'Hello, World', 10 message_end:
  • 25. 25 #include <stdio.h> int main(void) { printf("Hello, World!n"); return 0; } Displaying “Hello, World!” in C
  • 28.
  • 29. 29 The Python Programming Language ● High-level programming language ● Named after BBC’s "Monty Python’s Flying Circus" show ● One of the most adopted languages world-wide ● Most TY products are powered by it aalhour.com
  • 30. 30 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for each_number in numbers: print(each_number) Example Python Program: Counting to 10
  • 31. Let’s take a break!
  • 33. 33 Demo Time! ● General walk through REPL.IT aalhour.com
  • 34. 8. Hello, World! Your First Python Program 34aalhour.com
  • 35. 35 Numbers in Python ● Create a new repl on REPL.IT ● Type in the main.py tab: print(“hello, world!”) ● Click on run >! aalhour.com
  • 36. 9. Numbers The Art of Calculating Stuff 36aalhour.com
  • 37. 37 Numbers in Python ● One of value types ● Demo: ○ Numbers in interactive mode ○ Basic arithmetic aalhour.com
  • 38. 38 Evaluation Order of Operations ● First, “*” and “/” are evaluated ● Then, “-” and “+” are evaluated ● All operations are evaluated left-to-right aalhour.com
  • 39. 39 Guess the result of the following: ● 9 * 9 - 9 * 10 / 15 ● 1 + 1 + 1 * 2 + 6 / 2 ● 10 + 1 * 2 - 4 / 20 ● 50 - 5 - 5 - 10 / 2 ● 1 + 2 - 5 * 3 - 7 + 4 * 9 / 12 aalhour.com
  • 40. 40 Grouping Calculations with Parentheses ● Used for separating calculations into distinct groups ● For example: ○ (10 * 2) + (5 - 3) / (4 + 2) ○ → 20 + 2 / 6 ○ → 20 + 0.333 ○ → 20.333 aalhour.com
  • 41. 41 Evaluation Order of Operations: Revisited! ● First, what is in “(” and “)” is evaluated ● Then, “*” and “/” are evaluated ● Then, “-” and “+” are evaluated ● All operations are evaluated left-to-right aalhour.com
  • 42. 42 Guess the result of the following: ● 9 * (9 - 9) * 10 / 15 ● (1 + 1 + 1) * (2 + 6) / 2 ● 10 + 1 * (2 - 4) / 20 ● 50 - 5 - (5 - 10) / 2 ● (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12 aalhour.com
  • 43. 10. Variables The Art of Naming Stuff 43aalhour.com
  • 44. 44 Variables in Python ● Used to give names to values ● You give names to stuff to refer to them later on in your program ● You give names to stuff using the “=” symbol, known as “assignment operator” ● Variable names must begin with a letter aalhour.com
  • 45. 45 ● Implement one plus one operations using variables Demo Time aalhour.com
  • 46. 46 Example usage: ● Calculate the average population for Earth in 2015 ● Give it a name ● Everytime you want to refer to it you just use the name rather than to recalculate it again Variables in Python aalhour.com
  • 47. 47 Break the calculation down using variables: ● (10 * 2) + (5 - 3) / (4 + 2) ● X + Y / Z ● Store result in “result” name Demo Time aalhour.com
  • 48. 48 Break the following calculations down into sub-calculations and store them into variables: ● 9 * (9 - 9) * 10 / 15 ● (1 + 1 + 1) * (2 + 6) / 2 ● 10 + 1 * (2 - 4) / 20 ● 50 - 5 - (5 - 10) / 2 ● (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12 Exercise aalhour.com
  • 49. 11. Strings The Art of Texting Stuff 49aalhour.com
  • 50. 50 ● Used to represent text in Python ● Examples: ○ “Hello, World!” ○ “My name is Ahmad.” ○ “Bier und Brezel.” ● Any text in between “” is a string in Python Strings in Python aalhour.com
  • 51. 51 ● Type in the following strings in the interactive shell: ○ “Hello, World!” ○ “My name is Ahmad.” ○ “Bier und Brezel.” ● Use all of the above with print ● Store all of the above in variables and then print them Demo Time aalhour.com
  • 52. 52 Print the following poem: Doubt thou the stars are fire; Doubt that the sun doth move; Doubt truth to be a liar; But never doubt I love. ― William Shakespeare, Hamlet Exercise aalhour.com
  • 53. Let’s take a break!
  • 54. 54 12. Functions The Art of Naming Computations aalhour.com
  • 55. 55 ● Just like how variables give name to values, functions give name to calculations/instructions ● It is easier to refer to a group of instructions with a name than write them all over again ● You need three main words to define functions: “def”, “<name>” and “return” Functions in Python aalhour.com
  • 56. 56 ● You know functions already! ● Print is a Python function that takes whatever value you’d like and prints it on the screen ● Print can take several values separated by commas, e.g.: ○ print(“My name is:”, “Slim Shady”) ○ print(“One plus one is:”, 2) Functions in Python aalhour.com
  • 57. 57 ● Define a new function ● Print William Shakespeare’s poem ● repl.it/@aalhour/WilliamShakespeare Demo Time aalhour.com
  • 58. 58 ● Define a new function ● Code the one plus one example in variables ● Return the result Demo Time aalhour.com
  • 59. 59 ● Define a function to calculate each of the following, with variables, and return the result: ○ 9 * (9 - 9) * 10 / 15 ○ (1 + 1 + 1) * (2 + 6) / 2 ○ 10 + 1 * (2 - 4) / 20 ○ 50 - 5 - (5 - 10) / 2 ○ (1 + 2) - 5 * (3 - 7 + 4) * 9 / 12 Exercise aalhour.com
  • 60. 60 ● Functions can take values as arguments! ● Useful for doing tasks with user input, for example: ○ Given 5 numbers, return the avg. ○ Given weight and height of a person, calculate their BMI. Functions in Python aalhour.com
  • 61. 61 ● Define a new function for printing different values ● Define a new function for calculating BMI given height and weight ● repl.it/@aalhour/FuncsWithVars Demo Time aalhour.com
  • 62. 62 ● Define a function that accepts two arguments and returns the result of their addition ● Define a function that takes five arguments and returns the average Exercise aalhour.com
  • 63. Lunch Break See you in an hour!
  • 64. 15 mins Recap and Review 45 mins Conditionals 45 mins While Loops and Collections 45 mins For Loops and Functions (again!) 30 mins Wrapping Up Plan After Lunch
  • 65. 13. Recap What Have We Learned So Far? 65aalhour.com
  • 66. 66 ● Numbers: 1, 2, 3 ● Order of operations: (, ), *, /, +, - ● Strings: “Hi!” ● Variables: x = 1 ● Functions: def greet(): print(“Hello, world!”) Recap aalhour.com
  • 67. 14. Conditionals The Art of Comparing Stuff 67aalhour.com
  • 68. 68 ● They are the Yes/No questions of programming ● The answer is either a True or a False ● These values are called Booleans ● Conditionals compare values together ● Using simple operators such as: ○ >, <, >=, <= and == Conditionals aalhour.com
  • 69. 69 Compare several numbers together and check the results: ● 1 < 10 ● 1 <= 10 ● 5 > 2 ● 5 >= 2 ● 1 == 1 ● 0 <= 0 Demo Time aalhour.com
  • 70. 70 Evaluate the following in your mind and then on REPL.IT: ● 1 + 1 + 1 + 1 + 1 > 4 ● 2 * 2 < 5 / 3 ● 5 * 3 >= 15 ● 10 / 2 == 5 ● (25 * 3) - 100 / 2 < (25 * 2) + 1 Exercise aalhour.com
  • 71. 71 ● First, what is in “(” and “)” is evaluated ● Then, “*” and “/” are evaluated ● Then, “-” and “+” are evaluated ● Lastly, comparisons are evaluated ○ “>”, “>=”, “<”, “<=”, “==” ● Operations get evaluated left-to-right Evaluation Order of Operations: Expanded aalhour.com
  • 72. 72 ● A Python statement for making decisions based on a condition ● In a nutshell: if this, then that ● For example: If your age is greater than 18, then you are allowed to enter the bar The If Statement aalhour.com
  • 73. 73 ● If old enough to enter bar, print “proceed to bar!”. ● If not old enough to enter bar, print “too young still!” Demo Time aalhour.com
  • 74. 74 Teenager Exercise 01: Define an “age” variable and insert your age. Write an if statement to display “teenager” if age is less than 21 Exercises aalhour.com
  • 75. 75 Exercises Positive Number 01: Define a “number” variable and insert a random value. Write an if statement to display “positive” if the number is greater than 0 aalhour.com
  • 76. 76 ● Expanded If-Statement for handling cases that don’t match the condition. ● In a nutshell: if this, then that; otherwise, something else ● For example: ○ If your age is greater than 18, then you are allowed to enter the bar; otherwise, you are asked to leave The If-Else Statement aalhour.com
  • 77. 77 Translate the following into Python: If old enough to enter bar then print “proceed to bar!” else print “please, leave!” Demo Time aalhour.com
  • 78. 78 ● Teenager Exercise 02: Expand the code and add an else block which prints “adult” if the teenager check is not met ● Positive Number 02: Expand the code and add an else block which prints “negative” if the positive check is not met Exercises aalhour.com
  • 79. 79 ● Teenager Exercise 03: Wrap the exercise’s code in a function that accepts an “age” argument and returns nothing. ● Positive Number 03: Wrap the exercise’s code in a function that accepts a “number” argument and returns nothing. Exercises aalhour.com
  • 80. Let’s take a break!
  • 81. 15. While Loops The Art of Repeating Stuff 81aalhour.com
  • 82. 82 ● Loops are good for repeating instructions for a number of times ● They’re good because we don’t have to duplicate code, but we just tell the program to keep repeating stuff ● Loops repeat stuff according to a condition as well While Loops aalhour.com
  • 83. 83 ● Example: ○ While my BMI is above 100, keep working out! ○ While my coffee is not empty, keep writing code! ● You need two words to loop stuff: ○ “while” and “break” ○ Break is used to stop looping or else you will loop forever! While Loops aalhour.com
  • 84. 84 while True: print(1) # Prints 1 forever while 1 == 1: print(1) # Prints 1 forever while 5 > 2: print(1) # Prints 1 forever Code Examples aalhour.com
  • 85. 85 # Prints 1 once, then stops while True: print(1) break # Prints 1 once, then stops while 1 == 1: print(1) break Code Examples aalhour.com
  • 86. 86 ● Print “Hello, World!” forever! ● Print your own name forever! ● Calculate the following formula and print the result forever: ○ 10 * 312 / 57 + 23 * 5 + 823 / 74 Play Time aalhour.com
  • 87. 87 ● To avoid running forever, we need to maintain a counter and a limit ● Counters are variables that keep track of how many times a loop ran ● Limits allow us to break out of the loop once the loop runs for a max. number of times Counters and Limits aalhour.com
  • 88. 88 counter = 1 while counter < 10: print(counter) counter = counter + 1 Code Example aalhour.com
  • 89. 89 ● Add a counter number and increment it inside the loop. Print the counter to show that its value changes. ● Add a limit check before the work with a break. Demo Time aalhour.com
  • 90. 90 ● Print numbers from 0 until 1 million ● Teenager Exercise 04: Define age variable and assign it to 1. Run the loop with the teenager check. The loop should print the age and then increment it until the age is no longer teeanger, after which the loop should terminate Exercises aalhour.com
  • 91. 91 ● You can ask for the user’s input using the built-in “input” function ● For example: input(“Enter a number:”) ● Useful for asking the user for data. User Input aalhour.com
  • 92. 92 ● Ask the user for their name and then print it out. ● Ask the user for their age and print it out with the statement: “Your age is:” Demo Time aalhour.com
  • 93. 93 Teenager Exercise 05: Ask the user for their age. Run the loop with the teenager check on the user input. The loop should print “You are still a teenager” alongside the age and then increment it until the age is no longer teeanger, after which the loop should terminate. Exercises aalhour.com
  • 94. 94 Teenager Exercise 06: Wrap the Teenager Exercise #05 with a function that asks the user for their age and then prints out the message: “You are still a teenager:” alongside their age. Increments the age number until the loop no longer runs. Exercises aalhour.com
  • 95. Let’s take a break!
  • 96. 16. Collections The Art of Grouping Stuff 96aalhour.com
  • 97. 97 ● Collections are a way of keeping items together, e.g.: bags! ● We will take a look at lists in Python ● Lists are good for memorizing the order in which we keep things too Collections aalhour.com
  • 98. 98 A list of numbers: [1, 2, 3, 4, 5] A list of strings: [“Alice”, “Bob”, “Claire”] A mixed list of things: [123, “Ahmad”, message] Examples of Collections aalhour.com
  • 99. 99 Anything in between “[” and “]” is considered a list A list can contain anything in Python: ● Numbers ● Strings ● Variables ● Other lists How can I create a collection? aalhour.com
  • 100. 100 ● Create a list of the English alphabet ● Create a list that contains your: ○ first name ○ last name ○ your lucky number ○ your current address ● Print the above lists using the print() function Exercises aalhour.com
  • 101. 101 ● Ranges in Python are useful functions for generating collections of numbers ● More like a shortcut ● Easy to use ● Example: ○ range(1, 10): generates a collection of all numbers from 1 until 9 (stops at 10 but doesn’t include it) Ranges aalhour.com
  • 102. 102 ● range() takes three arguments: ○ Start: number to start with ○ End: number to stop at ○ Step: increment size ● Examples: ○ range(0, 5, 1) → [0,1,2,3,4,5] ○ range(0, 6, 2) → [0, 2, 4] ○ range(0, 6, 3) → [0, 3] Ranges: In Detail aalhour.com
  • 103. 103 ● start = 0 by default, unless specified ● step = 1 by default, unless specified ● end is mandatory and must be always specified ● Examples: ○ range(6) → [0,1,2,3,4,5] ■ Same as: range(0, 6, 1) Ranges: Default Behavior aalhour.com
  • 104. 104 ● Generate a list of all odd numbers greater than 0 and less than 1000 ● Generate a list of all even numbers greater than 29 and less than 250 ● Generate a list of all numbers less than -1 and greater than -132 ● Generate a list of all even numbers less than -250 and greater than -277 Exercises aalhour.com
  • 105. Let’s take a break!
  • 106. 17. For Loops The Art of Iterating Over Collections 106aalhour.com
  • 107. 107 ● For loops are another way to apply the same computation more than once according to a check in your program ● Similar to While Loops but easier to maintain ○ No need for a counter ○ No need for a beaking check For Loops aalhour.com
  • 108. 108 For loops need a collection in order to… well, loop! :P Example: for every item in shopping cart, print it out on the screen: for item in [“Shoes”, “Tablet”]: print(item) For Loops aalhour.com
  • 109. 109 for number in [1, 2, 3, 4, 5]: print(number) for number in range(6): print(number) for person in [“AA”, “AM”, “DW”, “DV”]: print(person) For Loops: Examples aalhour.com
  • 110. 110 ● Syntax: ○ for <variable name> in <collection>: ■ List of commands ● The variable name can be whatever you want ● The collection can have whatever you want but it must be a collection, not anything else How do I make a for loop? aalhour.com
  • 111. 111 1. For every item in the collection: a. Assign the item to the variable name that the programmer wrote b. Enter the block c. Execute all commands d. Go to 1 and grab the next the item 2. If the collection is empty or has no more items to see, then exit the block How do for loops work? aalhour.com
  • 112. 112 for number in [1, 2, 3, 4, 5]: print(number) Loop execution log: number = 1 → print(1) number = 2 → print(2) number = 3 → print(3) number = 4 → print(4) number = 5 → print(5) Demo aalhour.com
  • 113. 113 ● Using range() and a for loop: ○ Print your name 25 times ○ Print “Hello, World!” 10 times Play time! aalhour.com
  • 114. 114 Teenager Exercise 01: Reloaded Ask the user for their age. Check if the user is a teenager. Run a for loop over a range of ages until an age value that is not a teenage number anymore. Run a for loop and display the “you’re a teenager” message according to the list of ages (range) Exercises aalhour.com
  • 115. 115 Teenager Exercise 02: Reloaded Wrap your solution for the “Teenager Exercise 01: Reloaded” exercise with a function that asks the user for their age and then prints out the message: “You are still a teenager:” alongside their age. Exercises aalhour.com
  • 116. Let’s take a break!
  • 117. 18. Functions: Reloaded The Art of Naming Computations 117aalhour.com
  • 118. 118 Let’s solve the FizzBuzz challenge! Functions: Reloaded aalhour.com
  • 120. 120 ● Numbers: 1, 2, 3 ● Order of operations: (, ), *, /, +, -, <, >, >=, <=, == ● Strings: “Hi!” ● Variables: x = 1 ● Functions: def greet(person): print(“Hello, ”, person) ● Conditionals: 1 >= 10 What You’ve Learned So Far aalhour.com
  • 121. 121 ● While Loops: while True: greet(“Ahmad”) ● Lists: [1, 2, 3, “Alice”, “Bob”] ● Ranges: range(10) → [1, 2, 3, …, 9] ● For Loops: for number in range(10): print(number) What You’ve Learned So Far aalhour.com
  • 123. 123 Online Courses ● Intro to Python - by Udacity ○ https://bit.ly/2N45h6F ○ 5 weeks long. Completely FREE. ● Intro to Python: Absolute Beginner - by edX ○ https://bit.ly/2NJg2MW ○ 5 weeks. Completely FREE. ● Python for Everybody - by Coursera ○ https://bit.ly/1KSzsbb ○ 7 weeks long. Only first seven days are free. Resources for Further Study aalhour.com
  • 124. 124 Resources for Further Study Interactive Learning ● Codecademy - Learn by Coding ○ https://www.codecademy.com ○ Completely Free. Books ● Think Python, 2nd edition ○ http://greenteapress.com/thinkpython2 ○ Completely Free Online. aalhour.com
  • 125. Thanks! Any questions? 125 Find me at: aalhour.com github.com/aalhour twitter.com/ahmad_alhour aalhour.com