AHS-TechClub-043013 - Avon High School Tech Crew

advertisement
V2012.13
Agenda
• Old Business
– Delete Files
• New Business
– Week 18 Topics:
•
•
•
•
•
•
Intro to HTML/CSS: Questions?
Summer Work
Letter to Hyland
Upcoming Schedule
Group Executive Committee
Introduction to Programming … Python
Avon High School Tech Club
2
HTML/CSS Class
QUESTIONS?
Avon High School Tech Club
3
Tech Club Executive Committee
• Next Year:
– Election of Officers
•
•
•
•
President
Vice President
Secretary
Treasurer
• Send me an email with interest
Avon High School Tech Club
4
Upcoming Schedule
•
•
•
•
Today: Intro to Python
May 7th: Intro to Java
May 14th: Intro to C# (Guest Speaker)
May 21st: Embedded Programming
Avon High School Tech Club
5
Intro to Programming … Reset!
• Language Targets
– Python, Java, C#
• Our Approach:
– Install Tools (if needed)
– Start with basic examples (for each language)
– Walk step-by-step through each example
• Explain each line of code
– Explain concepts
– Define Terms
– Challenges (for each language)
Avon High School Tech Club
6
Intro to Python
•
•
•
•
•
•
History
Brief Overview
Installation/Tools
Getting Started
Examples
Resources
Avon High School Tech Club
7
Avon High School Tech Club
8
Avon High School Tech Club
MONTY PYTHON’S FLYING CIRCUS
9
Python Overview
•
•
•
•
•
•
Over 20 years old
General-purpose, high-level language
Used in math, science, web development, etc.
Emphasizes code readability and simplicity
Dynamic typing
Runs on multiple platforms
Avon High School Tech Club
10
“Batteries Included Language”
• Python includes a
“Standard Library”
• A collection of modules
to make some set of
tasks simpler
• Very extensive, offering
a wide range of
facilities
Avon High School Tech Club
11
Python Overview - Strings
str = 'Hello World!'
print str
print str[0]
print str[2:5]
print str[2:]
print str * 2
print str + "TEST"
Avon High School Tech Club
# Prints complete string
# Prints first character of the string
# Prints characters starting from 3rd to 6th
# Prints string starting from 3rd character
# Prints string two times
# Prints concatenated string
12
Python Overview - Lists
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print list
print list[0]
print list[1:3]
print list[2:]
print tinylist * 2
print list + tinylist
Avon High School Tech Club
# Prints complete list
# Prints first element of the list
# Prints elements starting from 2nd to 4th
# Prints elements starting from 3rd element
# Prints list two times
# Prints concatenated lists
13
Python Overview - Dictionaries
• Dictionaries work like associative arrays or
hashes and consist of key-value pairs
dict = {'name': 'john','code':6734, 'dept': 'sales'}
print dict['one']
print dict[2]
print tinydict
print tinydict.keys()
tinydict.values()
Avon High School Tech Club
# Prints value for 'one' key
# Prints value for 2 key
# Prints complete dictionary
# Prints all the keys print
# Prints all the values
14
Python Overview - Functions
• Defining a function only gives it a name,
specifies the parameters that are to be included
in the function, and structures the blocks of
code.
• Once the basic structure of a function is
finalized, you can execute it by calling it from
another function or directly from the Python
prompt.
def functionName (parameters):
Avon High School Tech Club
15
Python Overview - Functions
# Function definition is here
function
parameter
def printme( str ):
"This prints a passed string into this function"
print str;
return;
# Now you can call printme function
printme("I'm first call to user defined function!");
printme("Again second call to the same function");
Avon High School Tech Club
16
Python Overview - Modules
• A module allows you to logically organize your
Python code. Grouping related code into a
module makes the code easier to understand
and use.
• Simply, a module is a file consisting of Python
code. A module can define functions, classes,
and variables. A module can also include
runnable code.
Avon High School Tech Club
17
Python Overview - Modules
• You can use any Python source file as a module
by executing an import statement in some other
Python source file. import has the following
syntax:
import modulename
Avon High School Tech Club
18
Getting Started with Python
• Download Python
– http://www.python.org/getit/
– Already installed with most Linux distributions
Avon High School Tech Club
19
Getting Started with Python
Avon High School Tech Club
20
Running a Python Program
1. Create a file with a .py extension
2. Add some code
3. At a terminal prompt, type:
python yourfile.py
Avon High School Tech Club
21
Resources
• Official Python Website
– http://www.python.org/
• Python 3 Documentation
– http://docs.python.org/3/library/index.html
• Learning
– CodeAcademy
• http://www.codecademy.com/tracks/python
– LearningPython.org
• http://www.learnpython.org/
– After Hours Programming Python
• http://www.afterhoursprogramming.com/tutorial/Python/Overview
Avon High School Tech Club
22
Python Tutorial
• Good Python Tutorial:
– Appears to be geared towards Python 2.7
– http://www.tutorialspoint.com/python/
Avon High School Tech Club
23
Download