SlideShare a Scribd company logo
Birds & Coconuts
Numbers & Variables
Level 1
Why Python?
Easy to read VersatileFast
Frets on Fire
fretsonfire.sourceforge.net
Random color art
jeremykun.com
Code School User Voice
>>>>>>
The Python Interpreter
30.5
30.5
This symbol means "write your code here"
This symbol points to the outcome
>>>
>>>
>>>
>>>
>>>
>>>
Mathematical Operators
3 * 5
15
30 / 6
5
multiplication division
3 + 5
8
addition 10 - 5
5
subtraction
2 ** 3
8
exponent -2 + -3
-5
negation
>>> 30.5>>>
Integers and Floats
35
35
int
30.5
float
An int is a
whole number
A float is a
decimal number
Here’s a little Python terminology.
>>>>>>
Order of Operations
PEMDAS: Parentheses Exponent Multiplication Division Addition Subtraction
These are the calculations happening first.
5 + 7 * 3
26
5 + 21
( 5 + 7 ) * 3
36
12 * 3Behind
the
scenes
>>>
Let’s use some math to figure out if this swallow can carry this coconut!
Can a Swallow Carry a Coconut?
So, 1 swallow can carry 20 grams
What we know: A swallow weighs 60g and can carry 1/3 of its weight.
…but a coconut weighs 1450 grams
20
Swallow’s weight in grams Divide by 3
60 / 3
>>>
Let’s try to figure out how many swallows it takes to carry 1 coconut.
1450 /
Coconut weight Divide by 3Swallow’s weight
24.17 / 3
That number seems way too low.
Let’s look at what happened behind the scenes:
8.06
1450 / 60 / 3
We wanted 60/3 to happen first — we can add parentheses to fix this.
How Many Swallows Can Carry a Coconut?
60 / 3
What we know: A swallow weighs 60g and can carry 1/3 of its weight.
>>>
How many swallows does it take to carry 1 coconut?
Using Correct Order of Operations
1450 /
Coconut weight Divide by 3Swallow’s weight
That’s a lot of swallows!
72.5
1450 / ( 20 )
60 / 3 )(
What we know: A swallow weighs 60g and can carry 1/3 of its weight.
>>>
>>>
>>>
Let’s see if we can get closer to 1 swallow with other fruits.
What Other Fruits Can a Swallow Carry?
Great!
We found one that
works!
6.4# swallows per apple: 128 /
0.4# swallows per cherry: 8 /
# swallows per coconut: 1450 / 72.5
Seems like we’re
repeating this a lot
( 60 / 3 )
( 60 / 3 )
( 60 / 3 )
>>>
>>>
>>>
Creating a Variable in Python
>>>
Less repeated calculations
More organized
swallow_limit = 60 / 3
# swallows per apple: 6.4
# swallows per cherry: 0.4
# swallows per coconut: 1450 / 72.5
variable name value to store
Use variables to store a value that can be used later in your program.
swallow_limit
swallow_limit
swallow_limit
128 /
8 /
>>>
>>>
>>>
Variables keep your code more readable and assign meaning to values.
Using Variables Assigns Meaning
num_per_cherry = 8 / swallow_limit
swallow_limit = 60 / 3
swallows_per_cherry
0.4
swallows_per_cherry =
As long as you’re not breaking these rules, you can name variables anything you want!
What Should I Name My Variables?
swallowLimit camel case, later words are capitalized
Pep 8 Style Guide does NOT recommend:
no spaces = 0 no spaces in the name
3mice, $mice no digits or special characters in front
swallow_limit lowercase, use underscores for spaces
Pep 8 Style Guide recommends:
Check Pep 8 style guide here - http://go.codeschool.com/pep8-styleguide
Step 1: Declare variables for each value and find out the macaw’s carrying limit.
Can a Macaw Carry a Coconut?
>>>
>>>
>>>
>>>
>>>
300
Notice our variables
are descriptive,
but we’re still using
abbreviations where
appropriate.
coco_wt = 1450
macaw_wt = 900
perc = 1/3
macaw_limit = macaw_wt * perc
macaw_limit
Can a Macaw Carry a Coconut?
Step 2: Divide the coconut’s weight by the limit.
4.8
>>> num_macaws
>>> num_macaws = coco_wt/macaw_limit
>>>
>>>
# macaws needed to carry a coconut
>>>
>>>
coco_wt = 1450
macaw_wt = 900
perc = 1/3
macaw_limit = macaw_wt * perc
>>>
>>>
>>>
Occasionally, we will want to use modules containing functionality that is not built in to
the Python language.
Importing Modules — Extra Functionality
5
import math
This is importing extra math functions
math.ceil(num_macaws)
num_macaws = 4.8
ceil() is short for ceiling, which rounds up
Check out Python libraries here - http://go.codeschool.com/python-libraries
>>>
>>>
>>>
>>>
>>>
>>>
5
coco_wt = 1450
macaw_wt = 900
perc = 1/3
macaw_limit = macaw_wt * perc
num_macaws = coco_wt/macaw_limit
>>>
math.ceil(num_macaws)
import math
Step 3: Use the ceiling function to round up.
Can a Macaw Carry a Coconut?
Spam & Strings
Strings
Level 2
Creating Strings
>>>string
'Hello World'
Strings are a sequence of characters that can store letters, numbers, or a combination — anything!
Create a string with quotes
>>> "SPAM83"
'SPAM83'
Single or double quotes work —
just be consistent
string'Hello World'
String Concatenation With +
We can combine (or concatenate) strings by using the + operator.
last_name = 'Python'>>>
'MontyPython'
first_name = 'Monty'>>>
full_name = first_name +>>>
full_name>>>
Need to add a space!
last_name
Concatenating a Space
last_name = 'Python'>>>
'Monty Python'
first_name = 'Monty'>>>
full_name = first_name +>>>
full_name>>>
We can
concatenate a
space character
between the words
last_name' ' +
Moving Our Code to a Script File
last_name = 'Python'
first_name = 'Monty'
full_name = first_name +
full_name
Each line is entered
on the command line
last_name = 'Python'
first_name = 'Monty'
full_name = first_name + ' ' + last_name
Instead, we can put all lines into a single script file
script.py
But how can we output the value of full_name?
>>>
>>>
>>>
>>>
last_name' ' +
Output From Scripts With print()
print full_name
Monty Python
Everything in
1 script: script.py
print(full_name)
Prints whatever is
inside the ()
print(first_name, last_name)
print() as many things as you want,
just separate them with commas
Monty Python
last_name = 'Python'
first_name = 'Monty'
full_name = first_name + ' ' + last_name
print() automatically adds spaces
between arguments
In Python 2,
print doesn’t need ()
>>>
Running a Python Script
python script.py
This is the command to run Python
scripts
Monty Python
Put the name of your script file here
script.py
print(full_name)
last_name = 'Python'
first_name = 'Monty'
full_name = first_name + ' ' + last_name
Demo: Running a Python Script From the Console
script.py
Comments Describe What We’re Doing
Let’s write a script to describe what Monty Python is.
#means this line is a comment anddoesn’t get run
1969
name = 'Monty Python'
description = 'sketch comedy group'
# Describe the sketch comedy group
year =
Concatenating Strings and Ints
When we try to concatenate an int, year, with a string, we get an error.
script.py
TypeError: Can't convert 'int' object to str implicitly
Year is an int,
not a string
# Introduce them
1969
name = 'Monty Python'
description = 'sketch comedy group'
year =
# Describe the sketch comedy group
is a' description formed in yearsentence = name + '+ ' ++ '
Concatenating Strings and Ints
script.py
We could add quotes
and make the year a
string instead of an int
This will work, but it really makes sense to keep numbers as numbers.
'1969'
# Introduce them
name = 'Monty Python'
description = 'sketch comedy group'
year =
# Describe the sketch comedy group
is a' description formed in yearsentence = name + '+ ' ++ '
Turning an Int Into a String
script.py
Monty Python is a sketch comedy group formed in 1969
Instead, convert
the int to a string
when we
concatenate
with str()
print(sentence)
is a
# Introduce them
' description formed in yearstr( )sentence = name + '+ ' ++ '
name = 'Monty Python'
description = 'sketch comedy group'
year =
# Describe the sketch comedy group
1969
print() Casts to String Automatically
script.py
print() does string
conversions for us
Monty Python is a sketch comedy group formed in 1969
1969
# Introduce them
print( , , , , )is a description formed in year'name ' ' '
name = 'Monty Python'
description = 'sketch comedy group'
year =
# Describe the sketch comedy group
1969
Dealing With Quotes in Strings
# Describe Monty Python's work
famous_sketch = 'Hell's Grannies'
script.py
Syntax Error: invalid syntax
Interpreter thinks the
quote has ended and
doesn’t know what S is
# Describe Monty Python's work
famous_sketch1 = "Hell's Grannies"
script.py
Hell's Grannies
Start with '' instead —
now the ' no longer means
the end of the string
''
'
)print(famous_sketch1
# Describe Monty Python's work
famous_sketch1 = "
Hell's Grannies The Dead Parrot
script.py
Special Characters for Formatting
We want to add some more sketches and print them out
This works, but we want to format it better.
Let’s add another
famous sketch
)
famous_sketch2 = '
print( , famous_sketch2
Hell's Grannies"
The Dead Parrot'
famous_sketch1
# Describe Monty Python's work
famous_sketch1 = "
script.py
Special Characters — Newline
Add a newline
to make this look better
n is a special character that means new line.
This works, but we want to indent the titles.
Famous Work:
Hell's Grannies
The Dead Parrot
n
nThe Dead Parrot'
Hell's Grannies"
famous_sketch2 = '
print('Famous Work:', famous_sketch1, famous_sketch2)
Famous Work:
Hell's Grannies
The Dead Parrot
Special Characters — Tab
# Describe Monty Python's work
famous_sketch1 = "
script.py
Add a tab to indent and
make this look even
better
t is a special character that means tab.
n
n The Dead Parrot'
Hell's Grannies"
famous_sketch2 = '
print('Famous Work:', famous_sketch1, famous_sketch2)
t
t
>>>
>>>
Strings Behind the Scenes — a List of Characters
greeting =
>>> greeting[0] 'H'
greeting[11] '!'
A string is a list of characters, and each character in this list has a position or an index.
We can get each character by
calling its index with []
greeting[12] IndexError: string index out of range
Starts at 0
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10][11]
'H E L L O W O R L D !'
'H E L L O W O R L D !'
There are a few built-in string functions — like len(), which returns the length of a string and is very useful.
# print the length of greeting
greeting = 'HELLO WORLD!'
print( len(greeting) )
script.py
12
[0] [1] [2] [3] [4] [5] [6] [7] [8][9][10][11]
12
String Built-in Function — len()
word1 = 'Good'
end1 = word1[2] + word1[3]
print(end1)
script.py
The last half of the word:
characters at positions
[2] and [3]
'G o o d'
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
Good Evening
od
od ning
The Man Who Only Says Ends of Words
>>>
word = "P y t h o n"
[0] [1] [2] [3] [4] [5]
word[2:5] tho
Boundary
starts before
index 2
Boundary
ends before
index 5
Start
boundary
End
boundary
Using Slices to Access Parts of a String
>>>>>>
>>>>>>
o d
Slice Formula and Shortcuts
word1 ='G o o d'
[0] [1] [2] [3]
word1[0:2] G o
slice formula: variable [start : end+1]
word1[2:4] G oo d
Shortcuts:
word1[:2] G o
Means from start to position
[0] [1] [2] [3]
word1 ='G o o d'
word1[2:]
Means from position to end
Good
Go
Good
od
'G o o d'
word1 = 'Good'
end1 =
script.py
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
Replace this with a slice
word1[2:4]
od
Good
od
Incorporating String Slices Into Our Solution
print(end1)
word1[3]+word1[2]
Using the String Slice Shortcut
'G o o d'
word1 = 'Good'
end1 = word1[2:]
script.py
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
print(end1, end2)
word2 = 'Evening'
end2 = word2[3:]
Improved this with a
shortcut
od ning
It would be great if we didn’t have to know the halfway points were at 2 and 3…
Good Evening
od ning
The Index at the Halfway Point
The len() function will let us calculate the halfway index of our word.
'G o o d'
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
script.py
# Calculate the halfway index
half1 = len(word1)/
half2 = len(word2)/
PROBLEM: indexes have to be
integers — floats won’t work!
half1 is 2.0
half2 is 3.5
Good Evening
od ning
word2 = 'Evening'
2
2
word1 = 'Good'
The Index at the Halfway Point
// 2 division signs means integer division in Python.
'G o o d'
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
script.py
// Also rounds down to the
nearest integer
half1 is
4//2 = 2
half2 is
7//2 = 3
// Means integer division
Integer division vs floor
division. Be consistent if
we cover in Level 1.
In Python 2,
single division /
is int division unless
there are floats involved
# Calculate the halfway index
half1 = len(word1)/
half2 = len(word2)/
word2 = 'Evening'
2
2
/
/
word1 = 'Good'
Making Our Program More Reusable
Calculating the halfway index makes our logic reusable.
od ning
word2[half2:]
script.py
word1[half1:]
'G o o d'
[0] [1] [2] [3]
'E v e n i n g'
[0] [1] [2] [3] [4] [5] [6]
half1 is
4//2 = 2
half2 is
7//2 = 3
Good Evening
od ning
half1 = len(word1)/ 2/
word1 = 'Good'
end1 = word1[2:]
half2 = len(word2)/
word2 = 'Evening'
2/
end2 = word2[3:]
print(end1, end2)
Conditional Rules of Engagement
Conditionals & Input
Level 3
Extended Battle Rules
if there's more than 10 knights
Trojan Rabbit!
otherwise
if there's less than 3 knights
Retreat!
>>>
>>>
>>>
>>>
>>>
There are 6 comparators in Python:
Comparison Operators
<
less than
<=
less than
equal to
==
equal to
!=
not
equal to
>=
greater than
equal to
>
greater than
True5 < 10
Is 5 less than 10 ??
5 == 10
Is 5 equal to 10 ??
False
name = 'Pam'
Is name equal to Jim ??
name == 'Jim'
name != 'Jim'
Is name NOT equal to Jim ??
True
False
Setting the name variable
equal to 'Pam'
>>>>>>>>>
>>>>>>>>>
Here’s the output of evaluating all 6 comparisons:
Comparison Operator Outputs
5 < 10
True
5 == 10
False
5 > 10
False
5 <= 10
True
5 != 10
True
5 >= 10
False
>>>
>>>
In programming, a boolean is a type that can only be True or False.
Booleans
True booleans
is_raining = True
is_raining
True
False
Capital T and Capital F
script.py
Conditional — if, then
# Battle Rules
num_knights =
Then do this
Then this
Retreat!
Raise the white flag!
An if statement lets us decide what to do: if True, then do this.
If True:True
Any indented code that
comes after an if
statement is called a
code block
2
print('Retreat!')
print('Raise the white flag!')
if num_knights < 3:
script.py
Conditional — if, then
# Battle Rules
num_knights =
False
Because the
conditional is False,
this block doesn’t run
Nothing happens…
*crickets*
An if statement lets us decide what to do: if False, then don’t do this.
4
print('Retreat!')
print('Raise the white flag!')
if num_knights < 3:
script.py
The code continues to run as usual, line by line, after the conditional block.
The Program Continues After the Conditional
Knights of the Round Table!
# Battle Rules
num_knights =
Always this
This block doesn’t run,
but the code right
outside of the block
still does
False
4
print('Knights of the Round Table!')
print('Retreat!')
print('Raise the white flag!')
if num_knights < 3:
In Python, indent with 4 spaces. However, anything will work as long as you’re consistent.
Rules for Whitespace in Python
if num_knights == 1:
# Block start
print('Do this')
print('And this')
print('Always this')
IndentationError: unexpected indent
2 spaces
4 spaces
Irregular spacing is
a no-no!
The PEP 8 style guide recommends 4 spaces - http://go.codeschool.com/pep8-styleguide
Extended Battle Rules
otherwise
if there's less than 3 knights
Retreat!
Conditional — if False else
script.py
# Battle Rules
num_knights = 4
if num_knights < 3:
print('Retreat!')
else:
print('Truce?')
Truce?
If this statement is True,
then run the indented code below
Otherwise,
then run the indented code below
Conditionals — How to Check Another Condition?
script.py
Truce?
Otherwise if at least 10,
then Trojan Rabbit
X
else:
print('Truce?')
if num_knights < 3:
print('Retreat!')
# Battle Rules
num_knights = 10
elif Allows Checking Alternatives
Else sequences
will exit
as soon as a
statement is True…
…and continue
the program after
script.py
# Battle Rules
num_knights = 10
Trojan Rabbit
else:
print('Truce?')
elif num_knights >= 10:
print('Trojan Rabbit')
elif means otherwise if
elif day == 'Tuesday':
print('Taco Night')
We can have multiple elifs
if num_knights < 3:
print('Retreat!')
day = 'Wednesday'
King Arthur has decided:
Combining Conditionals With and/or
if num_knights < 3:
print('Retreat!')
if num_knights >= 10:
print('Trojan Rabbit!')
On all Mondays, we retreat
We can only use the Trojan Rabbit on Wednesday
(we’re renting it out on other days)
OR
if it’s a Monday
Retreat!
AND
it’s Wednesday
Trojan Rabbit!
if num_knights < 3 or day == "Monday":
print('Retreat!')
On all Mondays, or if we have less than 3 knights, we retreat.
Putting or in Our Program
If we have less than 3 knights OR If it’s a Monday Spelled out Monday, and
Wednesday on the next
slide.
if num_knights >= 10 and day == "Wednesday":
print('Trojan Rabbit!')
We can only use the Trojan Rabbit if we have at least 10 knights AND it’s Wednesday.
Putting and in Our Program
If we have at least 10 knights AND If it’s a Wednesday
Make it possible to combine comparisons or booleans.
Boolean Operators — and / or
True False
True
False
True
False
True
True
False
If 1 is True
or result will be True
True False
True
False
True
False
True
False
False
If 1 is False
and result will be False
and
and
and
or
or
or
script.py
Incorporating the Days of the Week
Checking day of the week
# Battle Rules
num_knights = 10
day = 'Wednesday'
if num_knights < 3 or day == 'Monday':
print('Retreat!')
elif num_knights >= 10 and day == 'Wednesday':
print('Trojan Rabbit!')
else:
print('Truce?')
User Input — With the input() Function
script.py
# Ask the user to input the day of the week
day = input('Enter the day of the week')
print('You entered:', day)
prints out this statement
and waits for user input
day saves the user's input
In Python 2,
raw_input() is used
instead of input()
Receiving User Input From Console
Just like we can print() text to the console, we can also get user input from the console.
script.py
User enters #, but it comes in as textChange (or cast) the string to an int
Enter the number of knights
You entered: 10
10
User enters 10
if num_knights < 3 or day == 'Monday':
print('Retreat!')
num_knights = int(input('Enter the number of knights'))
print('You entered:', num_knights)
# Ask the user to input the number of knights
Different Input and Conditionals Changes Output
script.py
# Battle Rules
num_knights = int(input('How many knights?'))
day = input('What day is it?'))
if num_knights < 3 or day == 'Monday':
print('Retreat!')
elif num_knights >= 10 and day == 'Wednesday':
print('Trojan Rabbit!')
else:
print('Truce?')
How many knights?
Retreat
2
What day is it? Tuesday
2How many knights?
Trojan Rabbit!
12
What day is it? Wednesday
Different user input
causes different
program flow:
1st run
2nd run
1st run 2nd run
Extended Battle Rules
killer bunny
Holy
Hand Grenade
num_knights >= 10
otherwise
num_knights < 3
script.py
Nested Conditionals — Ask Follow-up Questions
if num_knights < 3 or day == 'Monday':
print('Retreat!')
if num_knights >= 10 and day == 'Wednesday':
print('Trojan Rabbit!')
else:
print('Truce?')
# Original Battle Rules
First, find out if our enemy
is the killer bunny
If not,
then use the
original battle rules
Do the original battle rules here
# Battle Rules
num_knights = int(input('Enter number of knights')
day = input('Enter day of the week')
enemy = input('Enter type of enemy')
else:
if enemy == 'killer bunny':
print('Holy Hand Grenade!')
Nested Conditionals
script.py
Our final
Rules of Engagement
# Battle Rules
num_knights = int(input('Enter number of knights')
day = input('Enter day of the week')
enemy = input('Enter type of enemy')
else:
if num_knights < 3 or day == 'Monday':
print('Retreat!')
if num_knights >= 10 and day == 'Wednesday':
print('Trojan Rabbit!')
else:
print('Truce?')
# Original Battle Rules
if enemy == 'killer bunny':
print('Holy Hand Grenade!')
Python

More Related Content

What's hot

Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Edureka!
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
Samir Mohanty
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
Edureka!
 
Python ppt
Python pptPython ppt
Python ppt
Anush verma
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
srinivasanr281952
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
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
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
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 Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Edureka!
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
Damian T. Gordon
 
Python
PythonPython
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
Srinivas Narasegouda
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Python
PythonPython
Python
SHIVAM VERMA
 
Python Programming
Python ProgrammingPython Programming
Python Programming
Saravanan T.M
 
Python
PythonPython

What's hot (20)

Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 
Python ppt
Python pptPython ppt
Python ppt
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
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
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
 
Python programming
Python  programmingPython  programming
Python programming
 
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 Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Python
PythonPython
Python
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python
PythonPython
Python
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python
PythonPython
Python
 

Viewers also liked

MI Visita a Secondlife
MI Visita a SecondlifeMI Visita a Secondlife
MI Visita a Secondlife
Limberg Roman
 
Presentación final Centro Comercial Plaza Novena
Presentación final Centro Comercial Plaza NovenaPresentación final Centro Comercial Plaza Novena
Presentación final Centro Comercial Plaza Novena
RAFAEL IGNACIO OCHOA CORTES
 
Balboa Sea Tower Presentación
Balboa Sea Tower PresentaciónBalboa Sea Tower Presentación
Balboa Sea Tower Presentación
RAFAEL IGNACIO OCHOA CORTES
 
ThiagoDetanico Resume 13May2016
ThiagoDetanico Resume 13May2016ThiagoDetanico Resume 13May2016
ThiagoDetanico Resume 13May2016Thiago Detanico
 
mod 5.4 publisher advisory board
mod 5.4 publisher advisory boardmod 5.4 publisher advisory board
mod 5.4 publisher advisory boardMichelle Lewis
 
Hoja de vida marco
Hoja de vida marcoHoja de vida marco
Hoja de vida marco
Marco Tulio Orduña
 
Spiritual and Psychological Inventory
Spiritual and Psychological InventorySpiritual and Psychological Inventory
Spiritual and Psychological Inventory
Tina Samaniego, MSHEP
 
Livro2016 esperanca viva
Livro2016 esperanca vivaLivro2016 esperanca viva
Livro2016 esperanca viva
Eden Serrano
 
Movers Boca Raton
Movers Boca RatonMovers Boca Raton
Movers Boca Raton
Boris Kreychman
 
Polimeros
PolimerosPolimeros
Edición de presentaciones electrónicas
Edición de presentaciones electrónicasEdición de presentaciones electrónicas
Edición de presentaciones electrónicas
jesus martinez
 
Manual de Paola en PowerPoint
Manual de Paola en PowerPointManual de Paola en PowerPoint
Manual de Paola en PowerPoint
Gustavo Luna Peña
 
Ariet michal ci26380976 unidad i
Ariet michal ci26380976 unidad iAriet michal ci26380976 unidad i
Ariet michal ci26380976 unidad i
Ariet Michal
 
Capacidades coordinativas universidad de los llanos icc
Capacidades coordinativas universidad de los llanos iccCapacidades coordinativas universidad de los llanos icc
Capacidades coordinativas universidad de los llanos icc
Nombre Apellidos
 
Finding Our Value in Lower Usage Numbers: An Examination of Reference Servic...
Finding Our Value in Lower Usage Numbers:  An Examination of Reference Servic...Finding Our Value in Lower Usage Numbers:  An Examination of Reference Servic...
Finding Our Value in Lower Usage Numbers: An Examination of Reference Servic...
Elizabeth Namei
 
Basierra trabajo final
Basierra trabajo finalBasierra trabajo final
Basierra trabajo final
Bertha Adriana Sierra Villaseñor
 
Tugasan kumpulan anova
Tugasan kumpulan anovaTugasan kumpulan anova
Tugasan kumpulan anova
praba karan
 
Kitchen gardening planning By Mr Allah Dad Khan Agriculture Consultant KPK P...
Kitchen gardening planning  By Mr Allah Dad Khan Agriculture Consultant KPK P...Kitchen gardening planning  By Mr Allah Dad Khan Agriculture Consultant KPK P...
Kitchen gardening planning By Mr Allah Dad Khan Agriculture Consultant KPK P...
Mr.Allah Dad Khan
 
Documento tecnico influenza
Documento tecnico influenzaDocumento tecnico influenza
Documento tecnico influenza
Uriel Orduña Perez
 
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
Mr.Allah Dad Khan
 

Viewers also liked (20)

MI Visita a Secondlife
MI Visita a SecondlifeMI Visita a Secondlife
MI Visita a Secondlife
 
Presentación final Centro Comercial Plaza Novena
Presentación final Centro Comercial Plaza NovenaPresentación final Centro Comercial Plaza Novena
Presentación final Centro Comercial Plaza Novena
 
Balboa Sea Tower Presentación
Balboa Sea Tower PresentaciónBalboa Sea Tower Presentación
Balboa Sea Tower Presentación
 
ThiagoDetanico Resume 13May2016
ThiagoDetanico Resume 13May2016ThiagoDetanico Resume 13May2016
ThiagoDetanico Resume 13May2016
 
mod 5.4 publisher advisory board
mod 5.4 publisher advisory boardmod 5.4 publisher advisory board
mod 5.4 publisher advisory board
 
Hoja de vida marco
Hoja de vida marcoHoja de vida marco
Hoja de vida marco
 
Spiritual and Psychological Inventory
Spiritual and Psychological InventorySpiritual and Psychological Inventory
Spiritual and Psychological Inventory
 
Livro2016 esperanca viva
Livro2016 esperanca vivaLivro2016 esperanca viva
Livro2016 esperanca viva
 
Movers Boca Raton
Movers Boca RatonMovers Boca Raton
Movers Boca Raton
 
Polimeros
PolimerosPolimeros
Polimeros
 
Edición de presentaciones electrónicas
Edición de presentaciones electrónicasEdición de presentaciones electrónicas
Edición de presentaciones electrónicas
 
Manual de Paola en PowerPoint
Manual de Paola en PowerPointManual de Paola en PowerPoint
Manual de Paola en PowerPoint
 
Ariet michal ci26380976 unidad i
Ariet michal ci26380976 unidad iAriet michal ci26380976 unidad i
Ariet michal ci26380976 unidad i
 
Capacidades coordinativas universidad de los llanos icc
Capacidades coordinativas universidad de los llanos iccCapacidades coordinativas universidad de los llanos icc
Capacidades coordinativas universidad de los llanos icc
 
Finding Our Value in Lower Usage Numbers: An Examination of Reference Servic...
Finding Our Value in Lower Usage Numbers:  An Examination of Reference Servic...Finding Our Value in Lower Usage Numbers:  An Examination of Reference Servic...
Finding Our Value in Lower Usage Numbers: An Examination of Reference Servic...
 
Basierra trabajo final
Basierra trabajo finalBasierra trabajo final
Basierra trabajo final
 
Tugasan kumpulan anova
Tugasan kumpulan anovaTugasan kumpulan anova
Tugasan kumpulan anova
 
Kitchen gardening planning By Mr Allah Dad Khan Agriculture Consultant KPK P...
Kitchen gardening planning  By Mr Allah Dad Khan Agriculture Consultant KPK P...Kitchen gardening planning  By Mr Allah Dad Khan Agriculture Consultant KPK P...
Kitchen gardening planning By Mr Allah Dad Khan Agriculture Consultant KPK P...
 
Documento tecnico influenza
Documento tecnico influenzaDocumento tecnico influenza
Documento tecnico influenza
 
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
Kitchen gardening role By Mr Allah Dad Khan Agriculture Consultant KPK Pakist...
 

Similar to Python

Python basics
Python basicsPython basics
Python basics
Himanshu Awasthi
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
Dan Bowen
 
Python language data types
Python language data typesPython language data types
Python language data types
James Wong
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Hoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
ysolanki78
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
Nicholas I
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
RohitSindhu10
 

Similar to Python (20)

Python basics
Python basicsPython basics
Python basics
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Python programing
Python programingPython programing
Python programing
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 

More from Helio Colombe

Reformadores - Reforma Protestante - Protestantismo
Reformadores - Reforma Protestante - ProtestantismoReformadores - Reforma Protestante - Protestantismo
Reformadores - Reforma Protestante - Protestantismo
Helio Colombe
 
Obra social e espiritual
Obra social e espiritualObra social e espiritual
Obra social e espiritual
Helio Colombe
 
The 21P/GIACOBINI-ZINNER COMET
The 21P/GIACOBINI-ZINNER COMETThe 21P/GIACOBINI-ZINNER COMET
The 21P/GIACOBINI-ZINNER COMET
Helio Colombe
 
1948 - Será uma coincidência ou Obra de Deus?
1948 - Será uma coincidência ou Obra de Deus?1948 - Será uma coincidência ou Obra de Deus?
1948 - Será uma coincidência ou Obra de Deus?
Helio Colombe
 
El Arte de Programar en R
El Arte de Programar en REl Arte de Programar en R
El Arte de Programar en R
Helio Colombe
 
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
Helio Colombe
 
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - PortuguêsPor que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
Helio Colombe
 
Curso de Python (Básico) - Português
Curso de Python (Básico) - PortuguêsCurso de Python (Básico) - Português
Curso de Python (Básico) - Português
Helio Colombe
 
El Islamismo al Descubierto - Norman Geisler
El Islamismo al Descubierto - Norman GeislerEl Islamismo al Descubierto - Norman Geisler
El Islamismo al Descubierto - Norman Geisler
Helio Colombe
 
Poder Espiritual - R. A. Torrey
Poder Espiritual - R. A. TorreyPoder Espiritual - R. A. Torrey
Poder Espiritual - R. A. Torrey
Helio Colombe
 
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
Helio Colombe
 
A Verdadeira História de ("nossa") Senhora Aparecida do Norte
A Verdadeira História de ("nossa") Senhora Aparecida do NorteA Verdadeira História de ("nossa") Senhora Aparecida do Norte
A Verdadeira História de ("nossa") Senhora Aparecida do Norte
Helio Colombe
 
Historia de la Iglesia Primitiva - Harry R. Boer
Historia de la Iglesia Primitiva - Harry R. BoerHistoria de la Iglesia Primitiva - Harry R. Boer
Historia de la Iglesia Primitiva - Harry R. Boer
Helio Colombe
 
Adobe Muse - Guia de referencia
Adobe Muse - Guia de referenciaAdobe Muse - Guia de referencia
Adobe Muse - Guia de referencia
Helio Colombe
 
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
Helio Colombe
 
Entendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
Entendamos 24 principios basicos para interpretar la Biblia - Walter HenrichsenEntendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
Entendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
Helio Colombe
 
O Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
O Batismo no Espírito Santo - Como recebê-lo / W. V. GrantO Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
O Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
Helio Colombe
 
Como recibir el Bautismo del Espíritu Santo - Gordon Lindsay
Como recibir el Bautismo del Espíritu Santo - Gordon LindsayComo recibir el Bautismo del Espíritu Santo - Gordon Lindsay
Como recibir el Bautismo del Espíritu Santo - Gordon Lindsay
Helio Colombe
 
Porqué NO es correcto el nombre JEHOVÁ
Porqué NO es correcto el nombre JEHOVÁPorqué NO es correcto el nombre JEHOVÁ
Porqué NO es correcto el nombre JEHOVÁ
Helio Colombe
 
Comunión con Dios - Cómo Fortalecerla o Restaurarla
Comunión con Dios - Cómo Fortalecerla o RestaurarlaComunión con Dios - Cómo Fortalecerla o Restaurarla
Comunión con Dios - Cómo Fortalecerla o Restaurarla
Helio Colombe
 

More from Helio Colombe (20)

Reformadores - Reforma Protestante - Protestantismo
Reformadores - Reforma Protestante - ProtestantismoReformadores - Reforma Protestante - Protestantismo
Reformadores - Reforma Protestante - Protestantismo
 
Obra social e espiritual
Obra social e espiritualObra social e espiritual
Obra social e espiritual
 
The 21P/GIACOBINI-ZINNER COMET
The 21P/GIACOBINI-ZINNER COMETThe 21P/GIACOBINI-ZINNER COMET
The 21P/GIACOBINI-ZINNER COMET
 
1948 - Será uma coincidência ou Obra de Deus?
1948 - Será uma coincidência ou Obra de Deus?1948 - Será uma coincidência ou Obra de Deus?
1948 - Será uma coincidência ou Obra de Deus?
 
El Arte de Programar en R
El Arte de Programar en REl Arte de Programar en R
El Arte de Programar en R
 
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
Esse poderia ser o dia que o apóstolo viu no Apocalipse!!! 2017
 
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - PortuguêsPor que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
Por que o arrebatamento da igreja deve ocorrer no ano novo judeu - Português
 
Curso de Python (Básico) - Português
Curso de Python (Básico) - PortuguêsCurso de Python (Básico) - Português
Curso de Python (Básico) - Português
 
El Islamismo al Descubierto - Norman Geisler
El Islamismo al Descubierto - Norman GeislerEl Islamismo al Descubierto - Norman Geisler
El Islamismo al Descubierto - Norman Geisler
 
Poder Espiritual - R. A. Torrey
Poder Espiritual - R. A. TorreyPoder Espiritual - R. A. Torrey
Poder Espiritual - R. A. Torrey
 
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
Hasta lo último de la Tierra - La historia biográfica de los misioneros - R...
 
A Verdadeira História de ("nossa") Senhora Aparecida do Norte
A Verdadeira História de ("nossa") Senhora Aparecida do NorteA Verdadeira História de ("nossa") Senhora Aparecida do Norte
A Verdadeira História de ("nossa") Senhora Aparecida do Norte
 
Historia de la Iglesia Primitiva - Harry R. Boer
Historia de la Iglesia Primitiva - Harry R. BoerHistoria de la Iglesia Primitiva - Harry R. Boer
Historia de la Iglesia Primitiva - Harry R. Boer
 
Adobe Muse - Guia de referencia
Adobe Muse - Guia de referenciaAdobe Muse - Guia de referencia
Adobe Muse - Guia de referencia
 
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
El choque de Civilizaciones y la Reconfiguración del Orden Mundial - Samuel H...
 
Entendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
Entendamos 24 principios basicos para interpretar la Biblia - Walter HenrichsenEntendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
Entendamos 24 principios basicos para interpretar la Biblia - Walter Henrichsen
 
O Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
O Batismo no Espírito Santo - Como recebê-lo / W. V. GrantO Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
O Batismo no Espírito Santo - Como recebê-lo / W. V. Grant
 
Como recibir el Bautismo del Espíritu Santo - Gordon Lindsay
Como recibir el Bautismo del Espíritu Santo - Gordon LindsayComo recibir el Bautismo del Espíritu Santo - Gordon Lindsay
Como recibir el Bautismo del Espíritu Santo - Gordon Lindsay
 
Porqué NO es correcto el nombre JEHOVÁ
Porqué NO es correcto el nombre JEHOVÁPorqué NO es correcto el nombre JEHOVÁ
Porqué NO es correcto el nombre JEHOVÁ
 
Comunión con Dios - Cómo Fortalecerla o Restaurarla
Comunión con Dios - Cómo Fortalecerla o RestaurarlaComunión con Dios - Cómo Fortalecerla o Restaurarla
Comunión con Dios - Cómo Fortalecerla o Restaurarla
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 

Python

  • 1.
  • 2. Birds & Coconuts Numbers & Variables Level 1
  • 3. Why Python? Easy to read VersatileFast Frets on Fire fretsonfire.sourceforge.net Random color art jeremykun.com Code School User Voice
  • 4. >>>>>> The Python Interpreter 30.5 30.5 This symbol means "write your code here" This symbol points to the outcome
  • 5. >>> >>> >>> >>> >>> >>> Mathematical Operators 3 * 5 15 30 / 6 5 multiplication division 3 + 5 8 addition 10 - 5 5 subtraction 2 ** 3 8 exponent -2 + -3 -5 negation
  • 6. >>> 30.5>>> Integers and Floats 35 35 int 30.5 float An int is a whole number A float is a decimal number Here’s a little Python terminology.
  • 7. >>>>>> Order of Operations PEMDAS: Parentheses Exponent Multiplication Division Addition Subtraction These are the calculations happening first. 5 + 7 * 3 26 5 + 21 ( 5 + 7 ) * 3 36 12 * 3Behind the scenes
  • 8. >>> Let’s use some math to figure out if this swallow can carry this coconut! Can a Swallow Carry a Coconut? So, 1 swallow can carry 20 grams What we know: A swallow weighs 60g and can carry 1/3 of its weight. …but a coconut weighs 1450 grams 20 Swallow’s weight in grams Divide by 3 60 / 3
  • 9. >>> Let’s try to figure out how many swallows it takes to carry 1 coconut. 1450 / Coconut weight Divide by 3Swallow’s weight 24.17 / 3 That number seems way too low. Let’s look at what happened behind the scenes: 8.06 1450 / 60 / 3 We wanted 60/3 to happen first — we can add parentheses to fix this. How Many Swallows Can Carry a Coconut? 60 / 3 What we know: A swallow weighs 60g and can carry 1/3 of its weight.
  • 10. >>> How many swallows does it take to carry 1 coconut? Using Correct Order of Operations 1450 / Coconut weight Divide by 3Swallow’s weight That’s a lot of swallows! 72.5 1450 / ( 20 ) 60 / 3 )( What we know: A swallow weighs 60g and can carry 1/3 of its weight.
  • 11.
  • 12. >>> >>> >>> Let’s see if we can get closer to 1 swallow with other fruits. What Other Fruits Can a Swallow Carry? Great! We found one that works! 6.4# swallows per apple: 128 / 0.4# swallows per cherry: 8 / # swallows per coconut: 1450 / 72.5 Seems like we’re repeating this a lot ( 60 / 3 ) ( 60 / 3 ) ( 60 / 3 )
  • 13. >>> >>> >>> Creating a Variable in Python >>> Less repeated calculations More organized swallow_limit = 60 / 3 # swallows per apple: 6.4 # swallows per cherry: 0.4 # swallows per coconut: 1450 / 72.5 variable name value to store Use variables to store a value that can be used later in your program. swallow_limit swallow_limit swallow_limit 128 / 8 /
  • 14. >>> >>> >>> Variables keep your code more readable and assign meaning to values. Using Variables Assigns Meaning num_per_cherry = 8 / swallow_limit swallow_limit = 60 / 3 swallows_per_cherry 0.4 swallows_per_cherry =
  • 15. As long as you’re not breaking these rules, you can name variables anything you want! What Should I Name My Variables? swallowLimit camel case, later words are capitalized Pep 8 Style Guide does NOT recommend: no spaces = 0 no spaces in the name 3mice, $mice no digits or special characters in front swallow_limit lowercase, use underscores for spaces Pep 8 Style Guide recommends: Check Pep 8 style guide here - http://go.codeschool.com/pep8-styleguide
  • 16. Step 1: Declare variables for each value and find out the macaw’s carrying limit. Can a Macaw Carry a Coconut? >>> >>> >>> >>> >>> 300 Notice our variables are descriptive, but we’re still using abbreviations where appropriate. coco_wt = 1450 macaw_wt = 900 perc = 1/3 macaw_limit = macaw_wt * perc macaw_limit
  • 17. Can a Macaw Carry a Coconut? Step 2: Divide the coconut’s weight by the limit. 4.8 >>> num_macaws >>> num_macaws = coco_wt/macaw_limit >>> >>> # macaws needed to carry a coconut >>> >>> coco_wt = 1450 macaw_wt = 900 perc = 1/3 macaw_limit = macaw_wt * perc
  • 18. >>> >>> >>> Occasionally, we will want to use modules containing functionality that is not built in to the Python language. Importing Modules — Extra Functionality 5 import math This is importing extra math functions math.ceil(num_macaws) num_macaws = 4.8 ceil() is short for ceiling, which rounds up Check out Python libraries here - http://go.codeschool.com/python-libraries
  • 19. >>> >>> >>> >>> >>> >>> 5 coco_wt = 1450 macaw_wt = 900 perc = 1/3 macaw_limit = macaw_wt * perc num_macaws = coco_wt/macaw_limit >>> math.ceil(num_macaws) import math Step 3: Use the ceiling function to round up. Can a Macaw Carry a Coconut?
  • 20.
  • 22. Creating Strings >>>string 'Hello World' Strings are a sequence of characters that can store letters, numbers, or a combination — anything! Create a string with quotes >>> "SPAM83" 'SPAM83' Single or double quotes work — just be consistent string'Hello World'
  • 23. String Concatenation With + We can combine (or concatenate) strings by using the + operator. last_name = 'Python'>>> 'MontyPython' first_name = 'Monty'>>> full_name = first_name +>>> full_name>>> Need to add a space! last_name
  • 24. Concatenating a Space last_name = 'Python'>>> 'Monty Python' first_name = 'Monty'>>> full_name = first_name +>>> full_name>>> We can concatenate a space character between the words last_name' ' +
  • 25. Moving Our Code to a Script File last_name = 'Python' first_name = 'Monty' full_name = first_name + full_name Each line is entered on the command line last_name = 'Python' first_name = 'Monty' full_name = first_name + ' ' + last_name Instead, we can put all lines into a single script file script.py But how can we output the value of full_name? >>> >>> >>> >>> last_name' ' +
  • 26. Output From Scripts With print() print full_name Monty Python Everything in 1 script: script.py print(full_name) Prints whatever is inside the () print(first_name, last_name) print() as many things as you want, just separate them with commas Monty Python last_name = 'Python' first_name = 'Monty' full_name = first_name + ' ' + last_name print() automatically adds spaces between arguments In Python 2, print doesn’t need ()
  • 27. >>> Running a Python Script python script.py This is the command to run Python scripts Monty Python Put the name of your script file here script.py print(full_name) last_name = 'Python' first_name = 'Monty' full_name = first_name + ' ' + last_name
  • 28. Demo: Running a Python Script From the Console
  • 29. script.py Comments Describe What We’re Doing Let’s write a script to describe what Monty Python is. #means this line is a comment anddoesn’t get run 1969 name = 'Monty Python' description = 'sketch comedy group' # Describe the sketch comedy group year =
  • 30. Concatenating Strings and Ints When we try to concatenate an int, year, with a string, we get an error. script.py TypeError: Can't convert 'int' object to str implicitly Year is an int, not a string # Introduce them 1969 name = 'Monty Python' description = 'sketch comedy group' year = # Describe the sketch comedy group is a' description formed in yearsentence = name + '+ ' ++ '
  • 31. Concatenating Strings and Ints script.py We could add quotes and make the year a string instead of an int This will work, but it really makes sense to keep numbers as numbers. '1969' # Introduce them name = 'Monty Python' description = 'sketch comedy group' year = # Describe the sketch comedy group is a' description formed in yearsentence = name + '+ ' ++ '
  • 32. Turning an Int Into a String script.py Monty Python is a sketch comedy group formed in 1969 Instead, convert the int to a string when we concatenate with str() print(sentence) is a # Introduce them ' description formed in yearstr( )sentence = name + '+ ' ++ ' name = 'Monty Python' description = 'sketch comedy group' year = # Describe the sketch comedy group 1969
  • 33. print() Casts to String Automatically script.py print() does string conversions for us Monty Python is a sketch comedy group formed in 1969 1969 # Introduce them print( , , , , )is a description formed in year'name ' ' ' name = 'Monty Python' description = 'sketch comedy group' year = # Describe the sketch comedy group 1969
  • 34. Dealing With Quotes in Strings # Describe Monty Python's work famous_sketch = 'Hell's Grannies' script.py Syntax Error: invalid syntax Interpreter thinks the quote has ended and doesn’t know what S is # Describe Monty Python's work famous_sketch1 = "Hell's Grannies" script.py Hell's Grannies Start with '' instead — now the ' no longer means the end of the string '' ' )print(famous_sketch1
  • 35. # Describe Monty Python's work famous_sketch1 = " Hell's Grannies The Dead Parrot script.py Special Characters for Formatting We want to add some more sketches and print them out This works, but we want to format it better. Let’s add another famous sketch ) famous_sketch2 = ' print( , famous_sketch2 Hell's Grannies" The Dead Parrot' famous_sketch1
  • 36. # Describe Monty Python's work famous_sketch1 = " script.py Special Characters — Newline Add a newline to make this look better n is a special character that means new line. This works, but we want to indent the titles. Famous Work: Hell's Grannies The Dead Parrot n nThe Dead Parrot' Hell's Grannies" famous_sketch2 = ' print('Famous Work:', famous_sketch1, famous_sketch2)
  • 37. Famous Work: Hell's Grannies The Dead Parrot Special Characters — Tab # Describe Monty Python's work famous_sketch1 = " script.py Add a tab to indent and make this look even better t is a special character that means tab. n n The Dead Parrot' Hell's Grannies" famous_sketch2 = ' print('Famous Work:', famous_sketch1, famous_sketch2) t t
  • 38.
  • 39. >>> >>> Strings Behind the Scenes — a List of Characters greeting = >>> greeting[0] 'H' greeting[11] '!' A string is a list of characters, and each character in this list has a position or an index. We can get each character by calling its index with [] greeting[12] IndexError: string index out of range Starts at 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10][11] 'H E L L O W O R L D !'
  • 40. 'H E L L O W O R L D !' There are a few built-in string functions — like len(), which returns the length of a string and is very useful. # print the length of greeting greeting = 'HELLO WORLD!' print( len(greeting) ) script.py 12 [0] [1] [2] [3] [4] [5] [6] [7] [8][9][10][11] 12 String Built-in Function — len()
  • 41. word1 = 'Good' end1 = word1[2] + word1[3] print(end1) script.py The last half of the word: characters at positions [2] and [3] 'G o o d' [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] Good Evening od od ning The Man Who Only Says Ends of Words
  • 42. >>> word = "P y t h o n" [0] [1] [2] [3] [4] [5] word[2:5] tho Boundary starts before index 2 Boundary ends before index 5 Start boundary End boundary Using Slices to Access Parts of a String
  • 43. >>>>>> >>>>>> o d Slice Formula and Shortcuts word1 ='G o o d' [0] [1] [2] [3] word1[0:2] G o slice formula: variable [start : end+1] word1[2:4] G oo d Shortcuts: word1[:2] G o Means from start to position [0] [1] [2] [3] word1 ='G o o d' word1[2:] Means from position to end Good Go Good od
  • 44. 'G o o d' word1 = 'Good' end1 = script.py [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] Replace this with a slice word1[2:4] od Good od Incorporating String Slices Into Our Solution print(end1) word1[3]+word1[2]
  • 45. Using the String Slice Shortcut 'G o o d' word1 = 'Good' end1 = word1[2:] script.py [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] print(end1, end2) word2 = 'Evening' end2 = word2[3:] Improved this with a shortcut od ning It would be great if we didn’t have to know the halfway points were at 2 and 3… Good Evening od ning
  • 46. The Index at the Halfway Point The len() function will let us calculate the halfway index of our word. 'G o o d' [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] script.py # Calculate the halfway index half1 = len(word1)/ half2 = len(word2)/ PROBLEM: indexes have to be integers — floats won’t work! half1 is 2.0 half2 is 3.5 Good Evening od ning word2 = 'Evening' 2 2 word1 = 'Good'
  • 47. The Index at the Halfway Point // 2 division signs means integer division in Python. 'G o o d' [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] script.py // Also rounds down to the nearest integer half1 is 4//2 = 2 half2 is 7//2 = 3 // Means integer division Integer division vs floor division. Be consistent if we cover in Level 1. In Python 2, single division / is int division unless there are floats involved # Calculate the halfway index half1 = len(word1)/ half2 = len(word2)/ word2 = 'Evening' 2 2 / / word1 = 'Good'
  • 48. Making Our Program More Reusable Calculating the halfway index makes our logic reusable. od ning word2[half2:] script.py word1[half1:] 'G o o d' [0] [1] [2] [3] 'E v e n i n g' [0] [1] [2] [3] [4] [5] [6] half1 is 4//2 = 2 half2 is 7//2 = 3 Good Evening od ning half1 = len(word1)/ 2/ word1 = 'Good' end1 = word1[2:] half2 = len(word2)/ word2 = 'Evening' 2/ end2 = word2[3:] print(end1, end2)
  • 49.
  • 50. Conditional Rules of Engagement Conditionals & Input Level 3
  • 51. Extended Battle Rules if there's more than 10 knights Trojan Rabbit! otherwise if there's less than 3 knights Retreat!
  • 52. >>> >>> >>> >>> >>> There are 6 comparators in Python: Comparison Operators < less than <= less than equal to == equal to != not equal to >= greater than equal to > greater than True5 < 10 Is 5 less than 10 ?? 5 == 10 Is 5 equal to 10 ?? False name = 'Pam' Is name equal to Jim ?? name == 'Jim' name != 'Jim' Is name NOT equal to Jim ?? True False Setting the name variable equal to 'Pam'
  • 53. >>>>>>>>> >>>>>>>>> Here’s the output of evaluating all 6 comparisons: Comparison Operator Outputs 5 < 10 True 5 == 10 False 5 > 10 False 5 <= 10 True 5 != 10 True 5 >= 10 False
  • 54. >>> >>> In programming, a boolean is a type that can only be True or False. Booleans True booleans is_raining = True is_raining True False Capital T and Capital F
  • 55. script.py Conditional — if, then # Battle Rules num_knights = Then do this Then this Retreat! Raise the white flag! An if statement lets us decide what to do: if True, then do this. If True:True Any indented code that comes after an if statement is called a code block 2 print('Retreat!') print('Raise the white flag!') if num_knights < 3:
  • 56. script.py Conditional — if, then # Battle Rules num_knights = False Because the conditional is False, this block doesn’t run Nothing happens… *crickets* An if statement lets us decide what to do: if False, then don’t do this. 4 print('Retreat!') print('Raise the white flag!') if num_knights < 3:
  • 57. script.py The code continues to run as usual, line by line, after the conditional block. The Program Continues After the Conditional Knights of the Round Table! # Battle Rules num_knights = Always this This block doesn’t run, but the code right outside of the block still does False 4 print('Knights of the Round Table!') print('Retreat!') print('Raise the white flag!') if num_knights < 3:
  • 58. In Python, indent with 4 spaces. However, anything will work as long as you’re consistent. Rules for Whitespace in Python if num_knights == 1: # Block start print('Do this') print('And this') print('Always this') IndentationError: unexpected indent 2 spaces 4 spaces Irregular spacing is a no-no! The PEP 8 style guide recommends 4 spaces - http://go.codeschool.com/pep8-styleguide
  • 59. Extended Battle Rules otherwise if there's less than 3 knights Retreat!
  • 60. Conditional — if False else script.py # Battle Rules num_knights = 4 if num_knights < 3: print('Retreat!') else: print('Truce?') Truce? If this statement is True, then run the indented code below Otherwise, then run the indented code below
  • 61.
  • 62. Conditionals — How to Check Another Condition? script.py Truce? Otherwise if at least 10, then Trojan Rabbit X else: print('Truce?') if num_knights < 3: print('Retreat!') # Battle Rules num_knights = 10
  • 63. elif Allows Checking Alternatives Else sequences will exit as soon as a statement is True… …and continue the program after script.py # Battle Rules num_knights = 10 Trojan Rabbit else: print('Truce?') elif num_knights >= 10: print('Trojan Rabbit') elif means otherwise if elif day == 'Tuesday': print('Taco Night') We can have multiple elifs if num_knights < 3: print('Retreat!') day = 'Wednesday'
  • 64. King Arthur has decided: Combining Conditionals With and/or if num_knights < 3: print('Retreat!') if num_knights >= 10: print('Trojan Rabbit!') On all Mondays, we retreat We can only use the Trojan Rabbit on Wednesday (we’re renting it out on other days) OR if it’s a Monday Retreat! AND it’s Wednesday Trojan Rabbit!
  • 65. if num_knights < 3 or day == "Monday": print('Retreat!') On all Mondays, or if we have less than 3 knights, we retreat. Putting or in Our Program If we have less than 3 knights OR If it’s a Monday Spelled out Monday, and Wednesday on the next slide.
  • 66. if num_knights >= 10 and day == "Wednesday": print('Trojan Rabbit!') We can only use the Trojan Rabbit if we have at least 10 knights AND it’s Wednesday. Putting and in Our Program If we have at least 10 knights AND If it’s a Wednesday
  • 67. Make it possible to combine comparisons or booleans. Boolean Operators — and / or True False True False True False True True False If 1 is True or result will be True True False True False True False True False False If 1 is False and result will be False and and and or or or
  • 68. script.py Incorporating the Days of the Week Checking day of the week # Battle Rules num_knights = 10 day = 'Wednesday' if num_knights < 3 or day == 'Monday': print('Retreat!') elif num_knights >= 10 and day == 'Wednesday': print('Trojan Rabbit!') else: print('Truce?')
  • 69. User Input — With the input() Function script.py # Ask the user to input the day of the week day = input('Enter the day of the week') print('You entered:', day) prints out this statement and waits for user input day saves the user's input In Python 2, raw_input() is used instead of input()
  • 70. Receiving User Input From Console Just like we can print() text to the console, we can also get user input from the console. script.py User enters #, but it comes in as textChange (or cast) the string to an int Enter the number of knights You entered: 10 10 User enters 10 if num_knights < 3 or day == 'Monday': print('Retreat!') num_knights = int(input('Enter the number of knights')) print('You entered:', num_knights) # Ask the user to input the number of knights
  • 71. Different Input and Conditionals Changes Output script.py # Battle Rules num_knights = int(input('How many knights?')) day = input('What day is it?')) if num_knights < 3 or day == 'Monday': print('Retreat!') elif num_knights >= 10 and day == 'Wednesday': print('Trojan Rabbit!') else: print('Truce?') How many knights? Retreat 2 What day is it? Tuesday 2How many knights? Trojan Rabbit! 12 What day is it? Wednesday Different user input causes different program flow: 1st run 2nd run 1st run 2nd run
  • 72. Extended Battle Rules killer bunny Holy Hand Grenade num_knights >= 10 otherwise num_knights < 3
  • 73. script.py Nested Conditionals — Ask Follow-up Questions if num_knights < 3 or day == 'Monday': print('Retreat!') if num_knights >= 10 and day == 'Wednesday': print('Trojan Rabbit!') else: print('Truce?') # Original Battle Rules First, find out if our enemy is the killer bunny If not, then use the original battle rules Do the original battle rules here # Battle Rules num_knights = int(input('Enter number of knights') day = input('Enter day of the week') enemy = input('Enter type of enemy') else: if enemy == 'killer bunny': print('Holy Hand Grenade!')
  • 74. Nested Conditionals script.py Our final Rules of Engagement # Battle Rules num_knights = int(input('Enter number of knights') day = input('Enter day of the week') enemy = input('Enter type of enemy') else: if num_knights < 3 or day == 'Monday': print('Retreat!') if num_knights >= 10 and day == 'Wednesday': print('Trojan Rabbit!') else: print('Truce?') # Original Battle Rules if enemy == 'killer bunny': print('Holy Hand Grenade!')