Python Mini-Course
University of Oklahoma
Department of Psychology
Day 1 – Lesson 2
Fundamentals of Programming
Languages
4/5/09Python Mini-Course: Day 1 - Lesson 21
Lesson objectives
1. Describe the basic structure of the
Python language
2. Use the IDLE interactive
interpreter
3. Identify three kinds of errors that
occur in programming and
describe how to correct them
4/5/09Python Mini-Course: Day 1 - Lesson 22
Formal languages
Designed for specific apps
Ex: mathematical notation
Have strict rules for syntax
 3 + 3 = 6
 3+ = 3$6 (bad syntax)
Are literal and unambiguous
Structure is critical
4/5/09Python Mini-Course: Day 1 - Lesson 23
Programming languages
Formal languages that are
designed to express computations
and algorithms
Low level
One step removed from the 1’s and
0’s used by the computer
High level
More human-friendly languages
4/5/09Python Mini-Course: Day 1 - Lesson 24
Translating
High level language must be
translated into low level language
by either:
Interpreter (at run-time)
Compiler (creates a file containing
executable object code)
Python is an interpreted language
4/5/09Python Mini-Course: Day 1 - Lesson 25
Starting IDLE
4/5/09Python Mini-Course: Day 1 - Lesson 26
Programs
Programs are sequences of
instructions
Input
Output
Math and data manipulation
Conditional execution
Repetition
4/5/09Python Mini-Course: Day 1 - Lesson 27
The “Hello, World” program
4/5/09Python Mini-Course: Day 1 - Lesson 28
Scripts
A script is a file that contains a
program in a high-level
language for an interpreter
Python scripts are text files
ending in .py
Create HelloWorld.py
4/5/09Python Mini-Course: Day 1 - Lesson 29
Executing scripts
Python scripts are run in a
“shell”
This can be IDLE, a terminal shell
(OS X, Linux, Unix), or a
command prompt window (MS
Windows)
Run HelloWorld.py in IDLE
4/5/09Python Mini-Course: Day 1 - Lesson 210
Debugging
You will make mistakes while
programming!
These mistakes are called
“bugs” and the process of
tracking them down and
eliminating them is debugging
4/5/09Python Mini-Course: Day 1 - Lesson 211
Syntax Errors
All programming languages are
picky about syntax
Try this:
1 + 2) + 3
Syntax errors can be identified
using automated code checking
(color coding) and by error
messages
4/5/09Python Mini-Course: Day 1 - Lesson 212
Runtime errors
Errors that occur when
program is running
Also called “exceptions”
Ex: runtime.py
Identified by testing the
program (this includes using
test modules)
4/5/09Python Mini-Course: Day 1 - Lesson 213
Semantic or logical error
Program runs (and does
exactly what you told it to do)
But you made a mistake in the
design or implementation
Identified by case-based
testing
4/5/09Python Mini-Course: Day 1 - Lesson 214

Lsn02 fundamentals

  • 1.
    Python Mini-Course University ofOklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09Python Mini-Course: Day 1 - Lesson 21
  • 2.
    Lesson objectives 1. Describethe basic structure of the Python language 2. Use the IDLE interactive interpreter 3. Identify three kinds of errors that occur in programming and describe how to correct them 4/5/09Python Mini-Course: Day 1 - Lesson 22
  • 3.
    Formal languages Designed forspecific apps Ex: mathematical notation Have strict rules for syntax  3 + 3 = 6  3+ = 3$6 (bad syntax) Are literal and unambiguous Structure is critical 4/5/09Python Mini-Course: Day 1 - Lesson 23
  • 4.
    Programming languages Formal languagesthat are designed to express computations and algorithms Low level One step removed from the 1’s and 0’s used by the computer High level More human-friendly languages 4/5/09Python Mini-Course: Day 1 - Lesson 24
  • 5.
    Translating High level languagemust be translated into low level language by either: Interpreter (at run-time) Compiler (creates a file containing executable object code) Python is an interpreted language 4/5/09Python Mini-Course: Day 1 - Lesson 25
  • 6.
  • 7.
    Programs Programs are sequencesof instructions Input Output Math and data manipulation Conditional execution Repetition 4/5/09Python Mini-Course: Day 1 - Lesson 27
  • 8.
    The “Hello, World”program 4/5/09Python Mini-Course: Day 1 - Lesson 28
  • 9.
    Scripts A script isa file that contains a program in a high-level language for an interpreter Python scripts are text files ending in .py Create HelloWorld.py 4/5/09Python Mini-Course: Day 1 - Lesson 29
  • 10.
    Executing scripts Python scriptsare run in a “shell” This can be IDLE, a terminal shell (OS X, Linux, Unix), or a command prompt window (MS Windows) Run HelloWorld.py in IDLE 4/5/09Python Mini-Course: Day 1 - Lesson 210
  • 11.
    Debugging You will makemistakes while programming! These mistakes are called “bugs” and the process of tracking them down and eliminating them is debugging 4/5/09Python Mini-Course: Day 1 - Lesson 211
  • 12.
    Syntax Errors All programminglanguages are picky about syntax Try this: 1 + 2) + 3 Syntax errors can be identified using automated code checking (color coding) and by error messages 4/5/09Python Mini-Course: Day 1 - Lesson 212
  • 13.
    Runtime errors Errors thatoccur when program is running Also called “exceptions” Ex: runtime.py Identified by testing the program (this includes using test modules) 4/5/09Python Mini-Course: Day 1 - Lesson 213
  • 14.
    Semantic or logicalerror Program runs (and does exactly what you told it to do) But you made a mistake in the design or implementation Identified by case-based testing 4/5/09Python Mini-Course: Day 1 - Lesson 214