SlideShare a Scribd company logo
Python 101
  Alan Tree 08/24/2011
What is Python?

● Python is a powerful scripting language developed by
  Guido van Rossum in the late 80's.
● Python is a fully functional language while maintaining
  readability and understandability.
● Python is a common language that ships with most 'nix
  distros.
● Python is very extendable 
● Python is both dynamically typed and strongly typed at
  the same time.
Why Python?

● Readability
● Easy to learn
● Easy to write
● Cross platform
● Powerful
● Extensive uses in many areas of development
Who uses Python?

● Google
● Yahoo
● YouTube
● Industrial Light and Magic
● Disney
● EVE Online
● RackSpace
● AstraZeneca
● HoneyWell
Popular Applications using Python

● Google 
● Yahoo
● Blender
● GIMP
● BitTorrent
● Civ 4 
● BattleField 2 
● Eve Online
● Ubuntu Package Manager
Other uses for Python

1. IT - Various scripting tasks ('nix, OSX, Windows)
2. Web Development (Django, pylons, Grok, TurboGears,
   CherryPy, Flask, Google App Engine)
3. Game Development (Panda3d, pyGame, Pyglet, PIL,
   Python-Ogre, Soya3d)
4. Desktop Development (GUI development)
Ease of use
IDLE

● Able to modify code and run code directly from editor.
● Code is stored in simple text files with the .py extension.
● No open and close statements or curly braces. Indention
  determines blocks of code. 
● Comments are achieved with '#' 
Basics
Variables and DataTypes
Strings

s = 'alan'
 
s = "alan"
 
s = 'al' + 'an'
>>> 'alan'
 
s = "%s%s" % ('al', 'an') 
>>> 'alan'
Integers

x=2
 
y=4
 
z=x+y
 
z=z/2
>>> 3
 

 
 
Floats

z = 0.1
 
y = 1.2
 
m = z+y
>>> 1.3
 

 
Dict

t = {}
 
t = {'name':'alan', 'age':30}
List

l = []
 
l  = ['alan', '30']
 
l = ['alan', 30, 'apples', {'lname':'tree'}]
Tuple 

t = ['alan', 30]
 
t[1] = 5
Loops

while (condition):
    do this
 
for i in range (100): 
    do this a bunch
 
peeps_list = ['alan', 'joe', 'frank']
for i in peeps_list:
    print i
 
Conditionals

if condition:
    do something
 

if condition:
    do this
else:
    do that
 



 
Functions

def my_function():
    print "this is my function"
    return 
 
my_function()
>>> this is my function
Codez time
Hello World

print "Hello World"
Hello {Your name here}

your_name = "Alan"
 
print "Hello %s" % (your_name)
Hello {What is your name?}

your_name = raw_input ("What is your name? : ")
 
print "Hello %s" % (your_name)
Hello Conditional

your_age = int(raw_input("How old are you? :"))
 
if your_age >= 30:
    print "hmm, getting up there arn't we?"
else:
    print "young grass hopper!"
 
Hello {While Loop}

your_name = ""
 
while your_name != "Alan":
    your_name = raw_input ("What is your name? : ")

print "Access Granted!!!"
     
Questions?
Workshop 'Easy'

     Hi - Low
Write a program that will:

Guess a random number and have the user try to guess that
random number by providing the clues 'go higher' or 
'go lower' depending on the user's guess.
 
You will need this at the top of your program:
import random
 
You will need to get your random number like this:
random_number = random.randint(1,10)

 
 
Write a program that will:

Guess a random number and have the user try to guess that
random number by providing the clues 'go higher' or 
'go lower' depending on the user's guess. 
 
Hint:
import random
your_guess = 0
random_number = random.randint(1,10)
while {something doesn't match...}:
Workshop 'Easy' Solution:

import random
guess = 0
number = random.randint(1,10)

print "I have chosen a number between 1 and 10. Try to guess it!"

while guess != number :
  guess = int(raw_input("Your guess? :"))

  if guess < number:
      print "go higher"
  if guess > number:
      print "go lower"

print "You guessed it!"
Workshop 'Advanced'

   Fetch Search Results
Write a program that will:

Fetch the sports located in active search and display a menu
that will allow the user to choose a sport. Once a sport is
selected, have the user provide skills they can use to refine
their search. Once the search is conducted and an item is
found, present a menu so they may see more details about
that event. 
Things to note:
You will need these libraries:
import urllib
import json

You will need this base url:
base_url = 'http://api.amp.active.com/search?
f=activities&v=json&api_key=wuhmn9ye94xn3xnteudxsavw'

You will need to url encode the keywords:
url_with_keywords = urllib.quote_plus(key_words)

You will need to parse json:
json.loads(<json_string>)
 
You will need to use some of this:
"my_string".split("|")
"my_string".strip()

 
Workshop 'Advanced' HELP 1
import urllib
import json
base_url = 'http://api.amp.active.com/search?
f=activities&v=json&api_key=wuhmn9ye94xn3xnteudxsavw'
sports = ['Baseball', 'Basketball', 'Football', 'Golf', 'Outdoors', 'Running', 'Walking']

for sport in sports:
   print "%s - %s" % (sports.index(sport) + int(1), str(sport))

print "n"

the_sport = int(raw_input("What sport would you like to search for?"))
the_keywords = raw_input("Enter any keywords (or press ENTER for now): ")

print "n"

new_url = "%s&m=meta:channel%%3D%s" % (base_url, sports[the_sport])

if the_keywords.strip() != '':
    new_url = "%s&k=%s" % (new_url, urllib.quote_plus(the_keywords))
responses = urllib.urlopen(new_url).read()
responses = json.loads(responses)['_results']
Workshop 'Advanced' HELP 2
for i in range(1, len(responses)):
   print "%s - %s" % (i, responses[i]['title'].split('|')[0])

more_details = int(raw_input("Choose an event to see more details: "))

result = responses[more_details]
print "n"
print "Title: %s" % (result['title'].split('|')[0])
print "Location: %s, %s" % (result['meta']['city'], result['meta']['state'])
print "Start Date: %s" % (result['meta']['startDate'])
print "Assed ID: %s" % (result['meta']['assetTypeId'])
the end
questions?

More Related Content

Similar to Python 101

Python Novice to Ninja
Python Novice to NinjaPython Novice to Ninja
Python Novice to Ninja
Al Sayed Gamal
 
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
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
Marwan Osman
 
Lesson1 python an introduction
Lesson1 python an introductionLesson1 python an introduction
Lesson1 python an introduction
Arulalan T
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsRomain Guy
 
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
Sumit Raj
 
Programming with python
Programming with pythonProgramming with python
Programming with pythonsarogarage
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
Peter Friese
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsagniklal
 
Python basic
Python basicPython basic
Python basic
SOHIL SUNDARAM
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cdjacko91
 
Yahoo is open to developers
Yahoo is open to developersYahoo is open to developers
Yahoo is open to developers
Christian Heilmann
 
Programming in as3 the basics
Programming in as3 the basicsProgramming in as3 the basics
Programming in as3 the basics
Joseph Burchett
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
 
Python for dummies
Python for dummiesPython for dummies
Python for dummies
Roberto Stefanetti
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Python
PythonPython
Python
Shivam Gupta
 
Esplorando Google Assistant e Dialogflow
Esplorando Google Assistant e DialogflowEsplorando Google Assistant e Dialogflow
Esplorando Google Assistant e Dialogflow
Paolo Montrasio
 

Similar to Python 101 (20)

Python Novice to Ninja
Python Novice to NinjaPython Novice to Ninja
Python Novice to Ninja
 
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...
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Lesson1 python an introduction
Lesson1 python an introductionLesson1 python an introduction
Lesson1 python an introduction
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
 
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
 
Programming with python
Programming with pythonProgramming with python
Programming with python
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
Charming python
Charming pythonCharming python
Charming python
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
Python basic
Python basicPython basic
Python basic
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
 
Yahoo is open to developers
Yahoo is open to developersYahoo is open to developers
Yahoo is open to developers
 
Programming in as3 the basics
Programming in as3 the basicsProgramming in as3 the basics
Programming in as3 the basics
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Python for dummies
Python for dummiesPython for dummies
Python for dummies
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Python
PythonPython
Python
 
Esplorando Google Assistant e Dialogflow
Esplorando Google Assistant e DialogflowEsplorando Google Assistant e Dialogflow
Esplorando Google Assistant e Dialogflow
 

Recently uploaded

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
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 at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
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
 
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
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
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
 

Recently uploaded (20)

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
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 at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
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 !
 
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
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
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
 

Python 101

  • 1. Python 101 Alan Tree 08/24/2011
  • 2. What is Python? ● Python is a powerful scripting language developed by Guido van Rossum in the late 80's. ● Python is a fully functional language while maintaining readability and understandability. ● Python is a common language that ships with most 'nix distros. ● Python is very extendable  ● Python is both dynamically typed and strongly typed at the same time.
  • 3. Why Python? ● Readability ● Easy to learn ● Easy to write ● Cross platform ● Powerful ● Extensive uses in many areas of development
  • 4. Who uses Python? ● Google ● Yahoo ● YouTube ● Industrial Light and Magic ● Disney ● EVE Online ● RackSpace ● AstraZeneca ● HoneyWell
  • 5. Popular Applications using Python ● Google  ● Yahoo ● Blender ● GIMP ● BitTorrent ● Civ 4  ● BattleField 2  ● Eve Online ● Ubuntu Package Manager
  • 6. Other uses for Python 1. IT - Various scripting tasks ('nix, OSX, Windows) 2. Web Development (Django, pylons, Grok, TurboGears, CherryPy, Flask, Google App Engine) 3. Game Development (Panda3d, pyGame, Pyglet, PIL, Python-Ogre, Soya3d) 4. Desktop Development (GUI development)
  • 8. IDLE ● Able to modify code and run code directly from editor. ● Code is stored in simple text files with the .py extension. ● No open and close statements or curly braces. Indention determines blocks of code.  ● Comments are achieved with '#' 
  • 11. Strings s = 'alan'   s = "alan"   s = 'al' + 'an' >>> 'alan'   s = "%s%s" % ('al', 'an')  >>> 'alan'
  • 13. Floats z = 0.1   y = 1.2   m = z+y >>> 1.3    
  • 14. Dict t = {}   t = {'name':'alan', 'age':30}
  • 15. List l = []   l  = ['alan', '30']   l = ['alan', 30, 'apples', {'lname':'tree'}]
  • 16. Tuple  t = ['alan', 30]   t[1] = 5
  • 17. Loops while (condition):     do this   for i in range (100):      do this a bunch   peeps_list = ['alan', 'joe', 'frank'] for i in peeps_list:     print i  
  • 18. Conditionals if condition:     do something   if condition:     do this else:     do that    
  • 19. Functions def my_function():     print "this is my function"     return    my_function() >>> this is my function
  • 22. Hello {Your name here} your_name = "Alan"   print "Hello %s" % (your_name)
  • 23. Hello {What is your name?} your_name = raw_input ("What is your name? : ")   print "Hello %s" % (your_name)
  • 24. Hello Conditional your_age = int(raw_input("How old are you? :"))   if your_age >= 30:     print "hmm, getting up there arn't we?" else:     print "young grass hopper!"  
  • 25. Hello {While Loop} your_name = ""   while your_name != "Alan":     your_name = raw_input ("What is your name? : ") print "Access Granted!!!"      
  • 27. Workshop 'Easy' Hi - Low
  • 28. Write a program that will: Guess a random number and have the user try to guess that random number by providing the clues 'go higher' or  'go lower' depending on the user's guess.   You will need this at the top of your program: import random   You will need to get your random number like this: random_number = random.randint(1,10)    
  • 29. Write a program that will: Guess a random number and have the user try to guess that random number by providing the clues 'go higher' or  'go lower' depending on the user's guess.    Hint: import random your_guess = 0 random_number = random.randint(1,10) while {something doesn't match...}:
  • 30. Workshop 'Easy' Solution: import random guess = 0 number = random.randint(1,10) print "I have chosen a number between 1 and 10. Try to guess it!" while guess != number : guess = int(raw_input("Your guess? :")) if guess < number: print "go higher" if guess > number: print "go lower" print "You guessed it!"
  • 31. Workshop 'Advanced' Fetch Search Results
  • 32. Write a program that will: Fetch the sports located in active search and display a menu that will allow the user to choose a sport. Once a sport is selected, have the user provide skills they can use to refine their search. Once the search is conducted and an item is found, present a menu so they may see more details about that event. 
  • 33. Things to note: You will need these libraries: import urllib import json You will need this base url: base_url = 'http://api.amp.active.com/search? f=activities&v=json&api_key=wuhmn9ye94xn3xnteudxsavw' You will need to url encode the keywords: url_with_keywords = urllib.quote_plus(key_words) You will need to parse json: json.loads(<json_string>)   You will need to use some of this: "my_string".split("|") "my_string".strip()  
  • 34. Workshop 'Advanced' HELP 1 import urllib import json base_url = 'http://api.amp.active.com/search? f=activities&v=json&api_key=wuhmn9ye94xn3xnteudxsavw' sports = ['Baseball', 'Basketball', 'Football', 'Golf', 'Outdoors', 'Running', 'Walking'] for sport in sports: print "%s - %s" % (sports.index(sport) + int(1), str(sport)) print "n" the_sport = int(raw_input("What sport would you like to search for?")) the_keywords = raw_input("Enter any keywords (or press ENTER for now): ") print "n" new_url = "%s&m=meta:channel%%3D%s" % (base_url, sports[the_sport]) if the_keywords.strip() != '': new_url = "%s&k=%s" % (new_url, urllib.quote_plus(the_keywords)) responses = urllib.urlopen(new_url).read() responses = json.loads(responses)['_results']
  • 35. Workshop 'Advanced' HELP 2 for i in range(1, len(responses)): print "%s - %s" % (i, responses[i]['title'].split('|')[0]) more_details = int(raw_input("Choose an event to see more details: ")) result = responses[more_details] print "n" print "Title: %s" % (result['title'].split('|')[0]) print "Location: %s, %s" % (result['meta']['city'], result['meta']['state']) print "Start Date: %s" % (result['meta']['startDate']) print "Assed ID: %s" % (result['meta']['assetTypeId'])