Programming 101 with Python: an open-source, cross-platform, and fun language By J. Burton Browning,...

Preview:

Citation preview

Programming 101 Programming 101 with Python: an open-with Python: an open-

source, cross-source, cross-platform, and fun platform, and fun

languagelanguage

By J. Burton Browning, Ed.D.Copyright © J. Burton Browning

All rights reserved. If you use all or part of this work, please email or contact me with details.

Today we will discuss:

• Overview of my book as course text and history of the language

• A few basic features with Python

• Advanced features of Python—not just an introductory language!

History

• Developed by Guido van Rossum 1990• Actively maintained by him and others• New features and extensions added all the

time• Many books and websites with information• Name is based on Monty Python and not a

large snake!

Python features• Easy to learn• Great for RAD• Cross-platform and open-source• Compile to *.exe• GUI and other add-ins such as Pygame, Vpython, WX Windows,

etc.• Forces “clean” coding skills• Syntax similar to C/C++ and JAVA – can export to C• Free and commercial tools available• Used everywhere from application development and server

scripting to teaching

Course: Intro to Programming and Logic

• History of computers and programming• Prototype solutions (flowchart and pseudocode)• Program CLI applications• Basic control structures• Debugging• Advanced topics: GUI design, Add-in SDK’s,

COM integration, OOP, etc.

Two modes of operation

• Built-in IDE “IDLE”• “Line-by-line” or

interactive mode• “Multi-line” or script

mode – can save programs for reuse

• Helloi.avi

Variables and Math operators

• Variables are automatically “typed” to best fit. No variable declaration.

• Variables are immutable and not reused.

• Math operators similar to C++, JAVA, VB, etc. * = multiplication, + = addition, % modulus, etc.

Comment statements

• Pound sign ( # ) is used for single line comments.

• Multi-line comments are wrapped in triple quoted strings.

“”” any commentshere…“””

Examples

Single selection structure and Statement blocks

• Handled by indentation

• Forces “clean” code writing

• Format specifiers similar to C++/JAVA

Dual selection structure

• Similar to other languages

• Indentation defines statement blocks

Multiple selection structureSimilar to if, else if, else (could be switch or

select case in other languages).

elif is same as else if

While

• Similar to loop in other languages

Forfor x in range(10):

print x

name=“Smith”

for letter in name:

print letter

Functions

• def function_name():

any code for function…

Arrays

• Very rich collection of “array-like” structures

• Lists, tuples, and dictionaries

• More powerful than a standard array

• Teach same principles

• Easy to learn and implement

Dictionary example

Class design

• Can declare classes in same file or separate file.• Can focus on class design without other syntax

issues associated with other languages.• Put fun into class design!

Class example

GUI programming• Free SDK pythoncard.sourceforge.net• Similar to VB/VB.NET• Cross-platform unlike Visual Basic!• No special “dot net” framework needed!• Other GUI SDK’s available as well

Pygame• Free sdk from www.pygame.org for

game/simulation development.

• Many good/free tutorials available.

• Open-source games you can modify.

3D Graphics/animation• Vpython.org free

3d/animation sdk.

• Use for general

graphics study or

physics classes.

More information

• www.python.org• www.vpython.org• www.pygame.org• http://pythoncard.sourceforge.net/• http://www.activestate.com/products/komodo_ide/

Questions?Questions?

Thank you and good luck!

Text:Design, Logic, and Programming with

Python by James B. Browning

www.iuniverse.comwww.amazon.comBarnes and Noble

Recommended