SlideShare a Scribd company logo
1 of 12
Download to read offline
what if…
Basics: conditionals
The plan!
Basics: data types (and operations & calculations) ← recap
Basics: conditionals & iteration
Basics: lists, tuples, dictionaries
Basics: writing functions
Reading & writing files: opening, parsing & formats
Working with numbers: numpy & scipy
Making plots: matplotlib & pylab
… if you guys want more after all of that …
Writing better code: functions, pep8, classes
Working with numbers: Numpy & Scipy (advanced)
Other modules: Pandas & Scikit-learn
Interactive notebooks: ipython & jupyter
Advanced topics: virtual environments & version control
recap: ints, floats, strings & booleans
---- file contents ----
from __future__ import division
# the “+” operation works differently on strings and integers
print “Python”, 1 + 3, “the win!”
print “1” + “3”, “is an unlucky number.”
# integers (and floats) are great for maths
# we can use variables to store values
two = 3 - 1
print “Python is”, two “much fun.”
# strings are for text manipulation
first_numbers = “1” + “2” + “3”
print “The first few numbers are:”, first_numbers
print “Lots of nonsense:” first_numbers * 123
ints & floats
+ addition
- subtraction
* multiplication
/ division
** exponent
% modulus
strings
+ concatenate
* copy
… no spaces
… cannot begin with number: 1, 2 …
… cannot contain ?$@# (except _)
… cannot be a “built-in” name: and, or,
int, float, str, char, exec, file, open,
object, print, quit… (approx. 80
reserved names)
recap: ints, floats, strings & booleans
---- file contents ----
from __future__ import division
# “raw_input” always returns a string
number = raw_input(“Gimme a number:”)
print “Here is your number 3 times:” number * 3
# we can use functions to check and change the types
print “number is a:” type(number)
new_number = int(number)
print “new_number is a:” type(new_number)
print “Here is your number times 3 :” new_number * 3
# boolean values and equality testing
number = 3
print “Does number equal 3?”, number == 3
print “Is number > 10? ” number ?”, 3 > 10
int() convert to an integer
str() convert to a string
float() convert to a float
type() determine the type of a variable
= = equal
! = not equal
> greater than
>= greater or equal than
< less than
<= less or equal than
Some exercises...
- Write a script that asks the user for their height (in meters), and prints their
height in imperial:
- version 1: prints the result using only feet (1m = 3.28084ft)
- version 2: prints the result using feet and inches, to the nearest inch. (1ft = 12 inches)
Making choices
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
# here comes an “if else” block
if chairs >= lions:
# everything “indented” is part of the “true” block
print “You should be fine.”
# so you can write as much code as you want
print “Really, you’ll be fine!”
else:
print “Run away!!!”
# structure of an “if else” block
if boolean :
the “True” code goes here
else:
the “False” code goes here
Making choices: elif
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
# here comes an “if else” block.
if chairs > lions:
# everything “indented” is part of the “true” block
print “You should be fine.”
# so you can write as much code as you want
print “Really, you’ll be fine!”
elif chairs == lions: # “elif” is short for “else, if”
print “You’re OK.”
print “But should get some more chairs soon!”
else:
print “Run away!!!”
# structure of an “if elif else” block
# Only ONE block is executed!
if boolean :
the “True” code goes here
elif boolean :
next “True” code goes here
else:
the “False” code goes here
Making complex choices: nesting
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
hungry = raw_input(“Are the lions hungry? (yes/no)?:”)
# only worry about chairs if the lions are hungry
if hungry == ‘yes’:
# you can “nest” one “if” in another
if chairs > lions:
# notice the extra indentation?
print “You’ll be fine!”
else:
print “Run away!”
else:
print “The lions are not hungry right now.”
# structure of an “if else” block
if boolean :
if boolean :
… code goes here
else:
… code goes here
else:
… code goes here
Making complex choices: nesting
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
traps = int(raw_input(“How many traps do you have?:”))
bears = int(raw_input(“How many bears are there?:”))
# assume traps work against bears
# and chairs against lions
if (traps >= bears) and (chairs >= lions):
print “You’ll be fine!”
else:
print “Run away!”
# structure of an “if else” block
if (boolean and/or boolean…) :
the “True” code goes here
elif (boolean and/or boolean…) :
next “True” code goes here
else:
the “False” code goes here
Making complex choices: nesting
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
traps = int(raw_input(“How many traps do you have?:”))
bears = int(raw_input(“How many bears are there?:”))
# assume traps work against bears
# and chairs against lions
if (traps < bears) or (chairs < lions):
print “Run away!”
else:
print “You’ll be fine!”
# structure of an “if else” block
if (boolean and/or boolean…) :
the “True” code goes here
elif (boolean and/or boolean…) :
next “True” code goes here
else:
the “False” code goes here
Let’s write the following variants of the lion/chair/hungry program. They start as
above, but:
- If the ‘user’ does not write ‘yes’ or ‘no’ when answering ‘hungry?’, tells them that
their choice is not valid, and nothing else.
Exercise!
---- file good_advice.py ----
from __future__ import division
# “raw_input” always returns a string
chairs = int(raw_input(“How many chairs do you have?:”))
lions = int(raw_input(“How many lions are there?:”))
hungry = raw_input(“Are the lions hungry? (yes/no)?:”)
Moar exercises
- Write a script that asks the user 3 times to insert a number: First hours, next
minutes, and last seconds.
- The script should output the time in seconds only.
- Bonus: Write a script that does the opposite (i.e asks for seconds, and writes hr/min/sec)

More Related Content

What's hot

Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
An introduction to Python for absolute beginners
An introduction to Python for absolute beginnersAn introduction to Python for absolute beginners
An introduction to Python for absolute beginnersKálmán "KAMI" Szalai
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python pptPriyanka Pradhan
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
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 02Fariz Darari
 
Python-The programming Language
Python-The programming LanguagePython-The programming Language
Python-The programming LanguageRohan Gupta
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGDSCKYAMBOGO
 

What's hot (20)

Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
An introduction to Python for absolute beginners
An introduction to Python for absolute beginnersAn introduction to Python for absolute beginners
An introduction to Python for absolute beginners
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
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-The programming Language
Python-The programming LanguagePython-The programming Language
Python-The programming Language
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Python basic
Python basicPython basic
Python basic
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Python review2
Python review2Python review2
Python review2
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Python review2
Python review2Python review2
Python review2
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
Python for Beginners(v1)
Python for Beginners(v1)Python for Beginners(v1)
Python for Beginners(v1)
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban K
 

Viewers also liked

Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & listsMarc Gouw
 
Class 2: Welcome part 2
Class 2: Welcome part 2Class 2: Welcome part 2
Class 2: Welcome part 2Marc Gouw
 
Class 7a: Functions
Class 7a: FunctionsClass 7a: Functions
Class 7a: FunctionsMarc Gouw
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibMarc Gouw
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programmingMarc Gouw
 
Class 8a: Modules and imports
Class 8a: Modules and importsClass 8a: Modules and imports
Class 8a: Modules and importsMarc Gouw
 
Class 6: Lists & dictionaries
Class 6: Lists & dictionariesClass 6: Lists & dictionaries
Class 6: Lists & dictionariesMarc Gouw
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/OMarc Gouw
 
Introduction to SlideShare for Businesses
Introduction to SlideShare for BusinessesIntroduction to SlideShare for Businesses
Introduction to SlideShare for BusinessesSlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Viewers also liked (11)

Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
 
Class 2: Welcome part 2
Class 2: Welcome part 2Class 2: Welcome part 2
Class 2: Welcome part 2
 
Class 7a: Functions
Class 7a: FunctionsClass 7a: Functions
Class 7a: Functions
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
 
Class 8a: Modules and imports
Class 8a: Modules and importsClass 8a: Modules and imports
Class 8a: Modules and imports
 
Class 6: Lists & dictionaries
Class 6: Lists & dictionariesClass 6: Lists & dictionaries
Class 6: Lists & dictionaries
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/O
 
Introduction to SlideShare for Businesses
Introduction to SlideShare for BusinessesIntroduction to SlideShare for Businesses
Introduction to SlideShare for Businesses
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Basics conditionals iteration lists dictionaries functions files plotting"TITLE"Python conditionals data types modules pandas scikit interactive notebooks" TITLE"Ints floats strings booleans math operators conditionals files functions classes

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Python: легко и просто. Красиво решаем повседневные задачи.
Python: легко и просто. Красиво решаем повседневные задачи.Python: легко и просто. Красиво решаем повседневные задачи.
Python: легко и просто. Красиво решаем повседневные задачи.Python Meetup
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseAlexander Galkin
 
Python introduction
Python introductionPython introduction
Python introductionleela rani
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Python language data types
Python language data typesPython language data types
Python language data typesHarry Potter
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesFraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data typesJames Wong
 
Python language data types
Python language data typesPython language data types
Python language data typesYoung Alista
 
Python language data types
Python language data typesPython language data types
Python language data typesTony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesLuis Goldster
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
 

Similar to Basics conditionals iteration lists dictionaries functions files plotting"TITLE"Python conditionals data types modules pandas scikit interactive notebooks" TITLE"Ints floats strings booleans math operators conditionals files functions classes (20)

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python: легко и просто. Красиво решаем повседневные задачи.
Python: легко и просто. Красиво решаем повседневные задачи.Python: легко и просто. Красиво решаем повседневные задачи.
Python: легко и просто. Красиво решаем повседневные задачи.
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
Pythonintro
PythonintroPythonintro
Pythonintro
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
Python introduction
Python introductionPython introduction
Python introduction
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
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
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
Python slide
Python slidePython slide
Python slide
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 

Recently uploaded

Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Welcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayWelcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayZachary Labe
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trssuser06f238
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiologyDrAnita Sharma
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |aasikanpl
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.PraveenaKalaiselvan1
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Masticationvidulajaib
 
Cytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxCytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxVarshiniMK
 
Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫qfactory1
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024AyushiRastogi48
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxmalonesandreagweneth
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantadityabhardwaj282
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentationtahreemzahra82
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 

Recently uploaded (20)

Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort ServiceHot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Welcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayWelcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work Day
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 tr
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiology
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Mastication
 
Cytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxCytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptx
 
Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are important
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentation
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 

Basics conditionals iteration lists dictionaries functions files plotting"TITLE"Python conditionals data types modules pandas scikit interactive notebooks" TITLE"Ints floats strings booleans math operators conditionals files functions classes

  • 2. The plan! Basics: data types (and operations & calculations) ← recap Basics: conditionals & iteration Basics: lists, tuples, dictionaries Basics: writing functions Reading & writing files: opening, parsing & formats Working with numbers: numpy & scipy Making plots: matplotlib & pylab … if you guys want more after all of that … Writing better code: functions, pep8, classes Working with numbers: Numpy & Scipy (advanced) Other modules: Pandas & Scikit-learn Interactive notebooks: ipython & jupyter Advanced topics: virtual environments & version control
  • 3. recap: ints, floats, strings & booleans ---- file contents ---- from __future__ import division # the “+” operation works differently on strings and integers print “Python”, 1 + 3, “the win!” print “1” + “3”, “is an unlucky number.” # integers (and floats) are great for maths # we can use variables to store values two = 3 - 1 print “Python is”, two “much fun.” # strings are for text manipulation first_numbers = “1” + “2” + “3” print “The first few numbers are:”, first_numbers print “Lots of nonsense:” first_numbers * 123 ints & floats + addition - subtraction * multiplication / division ** exponent % modulus strings + concatenate * copy … no spaces … cannot begin with number: 1, 2 … … cannot contain ?$@# (except _) … cannot be a “built-in” name: and, or, int, float, str, char, exec, file, open, object, print, quit… (approx. 80 reserved names)
  • 4. recap: ints, floats, strings & booleans ---- file contents ---- from __future__ import division # “raw_input” always returns a string number = raw_input(“Gimme a number:”) print “Here is your number 3 times:” number * 3 # we can use functions to check and change the types print “number is a:” type(number) new_number = int(number) print “new_number is a:” type(new_number) print “Here is your number times 3 :” new_number * 3 # boolean values and equality testing number = 3 print “Does number equal 3?”, number == 3 print “Is number > 10? ” number ?”, 3 > 10 int() convert to an integer str() convert to a string float() convert to a float type() determine the type of a variable = = equal ! = not equal > greater than >= greater or equal than < less than <= less or equal than
  • 5. Some exercises... - Write a script that asks the user for their height (in meters), and prints their height in imperial: - version 1: prints the result using only feet (1m = 3.28084ft) - version 2: prints the result using feet and inches, to the nearest inch. (1ft = 12 inches)
  • 6. Making choices ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) # here comes an “if else” block if chairs >= lions: # everything “indented” is part of the “true” block print “You should be fine.” # so you can write as much code as you want print “Really, you’ll be fine!” else: print “Run away!!!” # structure of an “if else” block if boolean : the “True” code goes here else: the “False” code goes here
  • 7. Making choices: elif ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) # here comes an “if else” block. if chairs > lions: # everything “indented” is part of the “true” block print “You should be fine.” # so you can write as much code as you want print “Really, you’ll be fine!” elif chairs == lions: # “elif” is short for “else, if” print “You’re OK.” print “But should get some more chairs soon!” else: print “Run away!!!” # structure of an “if elif else” block # Only ONE block is executed! if boolean : the “True” code goes here elif boolean : next “True” code goes here else: the “False” code goes here
  • 8. Making complex choices: nesting ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) hungry = raw_input(“Are the lions hungry? (yes/no)?:”) # only worry about chairs if the lions are hungry if hungry == ‘yes’: # you can “nest” one “if” in another if chairs > lions: # notice the extra indentation? print “You’ll be fine!” else: print “Run away!” else: print “The lions are not hungry right now.” # structure of an “if else” block if boolean : if boolean : … code goes here else: … code goes here else: … code goes here
  • 9. Making complex choices: nesting ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) traps = int(raw_input(“How many traps do you have?:”)) bears = int(raw_input(“How many bears are there?:”)) # assume traps work against bears # and chairs against lions if (traps >= bears) and (chairs >= lions): print “You’ll be fine!” else: print “Run away!” # structure of an “if else” block if (boolean and/or boolean…) : the “True” code goes here elif (boolean and/or boolean…) : next “True” code goes here else: the “False” code goes here
  • 10. Making complex choices: nesting ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) traps = int(raw_input(“How many traps do you have?:”)) bears = int(raw_input(“How many bears are there?:”)) # assume traps work against bears # and chairs against lions if (traps < bears) or (chairs < lions): print “Run away!” else: print “You’ll be fine!” # structure of an “if else” block if (boolean and/or boolean…) : the “True” code goes here elif (boolean and/or boolean…) : next “True” code goes here else: the “False” code goes here
  • 11. Let’s write the following variants of the lion/chair/hungry program. They start as above, but: - If the ‘user’ does not write ‘yes’ or ‘no’ when answering ‘hungry?’, tells them that their choice is not valid, and nothing else. Exercise! ---- file good_advice.py ---- from __future__ import division # “raw_input” always returns a string chairs = int(raw_input(“How many chairs do you have?:”)) lions = int(raw_input(“How many lions are there?:”)) hungry = raw_input(“Are the lions hungry? (yes/no)?:”)
  • 12. Moar exercises - Write a script that asks the user 3 times to insert a number: First hours, next minutes, and last seconds. - The script should output the time in seconds only. - Bonus: Write a script that does the opposite (i.e asks for seconds, and writes hr/min/sec)