“One of the most important skills you will acquire is debugging.” – Downey, p. 5 Resource: http://docs.python.org/2/tutorial/errors.html
CONTACT: Mindy McAdams – http://mindymcadams.com/
PYTHONLEARNING TO PROGRAM
WHY LEARN TO PROGRAM?• An important skill in making things for online media: problem solving• Process of learning to program: Practice and improve your problem-solving skills• Thinking in a structured way• Learning how to find answers by a combination of online searching and trial-and-error
WHY PYTHON?Python is one ofthe most-usedprogramminglanguagestoday. Source: https://github.com/mjwillson/ProgLangVisualise
USING PYTHON • There are two ways to use Python: • Interactive mode • Script mode • In interactive mode, you type Python programs and the Python interpreter displays the result immediately …Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 2–3
USING PYTHON • There are two ways to use Python: • Interactive mode • Script mode • In script mode, you write code in a text file, save it, and then use the interpreter to execute (or run) the contents of the file (which is called a script) • Python scripts have filenames that end with .pySource: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 2–3
When you run a Python script (left) in the Pythoninterpreter, the output (but not the stored script) isdisplayed onscreen (right).
WHAT A PROGRAM DOES • Input: Get data from the keyboard, a file, or some other device • Output: Display data on the screen, or send data to a file or other device • Math: Perform basic mathematical operations like addition and multiplication • Conditional execution: Check for certain conditions and execute the appropriate code • Repetition: Perform some action repeatedly, usually with some variationSource: Think Python, by Allen B. Downey (O’Reilly Media: 2012), page 3
WHAT A PROGRAM DOES (2)• Input: (1) run a script; (2) raw_input• Output: (1) print; (2) create and write to text files• Math: +, –, /, *, %, >, <, >=, <=, ==• Conditional execution: if, elif, else• Repetition: for, whileYou will learn how to do each of these, which is pretty muchall there is to programming. (I’m lying a little bit.)
―Every program you’ve ever used, nomatter how complicated, is made up ofinstructions that look pretty much likethese. So you can think of programming asthe process of breaking a large, complextask into smaller and smaller subtasks untilthe subtasks are simple enough to beperformed with one of these basicinstructions.‖Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), page 4
DEBUGGING Errors are bugs. Finding and fixing them is debugging. • Syntax errors: Structure and rules, such as: ―Parentheses come in pairs‖ • Runtime errors: Appear while the program is running (these are called exceptions) • Semantic errors: Your script runs but does not do what you wanted it to doSource: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 4–5
In the practice of programming—of writingprograms—a lot of the work is in thedebugging.Each error becomes a puzzle to be solved.―Why doesn’t it work the way I want it towork?‖The process of learning to program is aprocess of problem-solving.
RESOURCES• Think Python, by Allen B. Downey http://www.greenteapress.com/thinkpython/• Learn Python the Hard Way, by Zed A. Shaw http://learnpythonthehardway.org/• Codecademy: Python http://www.codecademy.com/tracks/python
PYTHON LEARNING TO PROGRAMPresentation by Mindy McAdams, University of Florida [ 2012 ]