Python Introduction
Credit: Slides are modified with permission from Charles Severance at the University of Michigan.
This work is licensed under an Attribution-NonCommercial-ShareAlike 3.0 Unported License
lasacs.com
Act in haste and repent at leisure; code too soon and debug forever.
-- R. Kennington
lasacs.com
Writing good, efficient code requires
thought and planning
lasacs.com
lasacs.com
lasacs.com
lasacs.com
program that uses BLEND interface to automatically manage assignments
program that runs & checks student program submissions
lasacs.com
Users vs Programmers
lasacs.com
Computers want to be helpful...
lasacs.com
What is Code? Software? A Program?
A sequence of stored instructions
Program, noun:
A magic spell cast upon a computer to enable it to turn input into error messages.
lasacs.com
Program Steps or
Program Flow
lasacs.com
Python was/is developed by Guido van Rossum.
In the Python community, Van Rossum is known as a "Benevolent Dictator For Life" (BDFL).
lasacs.com
Beginning Programmers
lasacs.com
Beginning Programmers
Common Reaction when program does not work Cub Fan
lasacs.com
Programs do EXACTLY what you tell them to. They don't know any better.
lasacs.com
Programming can be frustrating.
lasacs.com
Early
Greek Programmers
lasacs.com
lasacs.com
What do we say?
lasacs.com
Statements and Expressions
x = 2
x = x + 2
print(x)
Variable
Operator
Literal
Function Name
Assignment Statement
Assignment with expression
Print statement
"parts of speech"
lasacs.com
to run Python code
Both are accessed using IDLE - Python's default Integrated Development and Learning Environment.
lasacs.com
Python Shell
What's next?
What I typed in
lasacs.com
Let's Talk to Python...
>>> x = 1
>>> print(x)
1
>>> y = x + 1
>>> print(y)
2
>>> y
2
lasacs.com
Sequential Steps
Program
x = 2
print(x)
2
x = x + 2
print(x)
4
output to screen.
x = 2
print(x)
x = x + 2
print(x)
When a program is running, it flows from one step to the next. We as programmers set up “paths” for the program to follow.
lasacs.com
Python Edit Window
Usually we enter our program into the Python Edit Window, save it to a file, and then tell python to run the program.
lasacs.com
Starting Python
2) type Idle
3) right click on Idle Python 3.x and select Pin to taskbar
1) click Start
From then on click on taskbar icon to start
lasacs.com
Edit Window &
Show line numbers
close Idle and open it again
lasacs.com
lasacs.com
lasacs.com
lasacs.com
lasacs.com
Useful IDLE Stuff
Quickly open a recent file.
Quickly indent/dedent or comment/uncomment
blocks of code.
Show line numbers
(required)
lasacs.com
lasacs.com
You will submit many of your Python programs using a web application called StudentDrop that was written by a former LASA students.
Programs submitted via StudentDrop end up on my computer so I can run and verify them (using a Python program that I wrote).
Before you can submit to StudentDrop, we'll first get you registered with StudentDrop.
lasacs.com
Requirements for your program name
You will submit many of your Python programs using PC2. You were emailed a username & password - click on the PC2 icon to login.
lasacs.com
PC2 submissions can only be made at school.
PC2 submissions are due when I have the PC2 judging program running (I usually keep it running at least until the beginning of the class after the class in which we have finished a PC2 assignment).
lasacs.com