This document provides an introduction to the Python programming language. It describes Python as a powerful and readable scripting language developed in the late 1980s. It is used widely in areas like web development, game development, and IT. The document explains Python's key features like readability, ease of use, cross-platform capabilities, and extensive standard library. It also provides examples of basic Python concepts like variables, data types, control flow, and functions.
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 '#'
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!"
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'])