csc 1010 programming for all lecture 2 introduction to python some material based on material from...
TRANSCRIPT
![Page 1: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/1.jpg)
CSC 1010Programming for All
Lecture 2Introduction to Python
Some material based on material fromMarty Stepp, Instructor, University of Washington
![Page 2: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/2.jpg)
Defining terms
• A program is a description in a programming language of a process that achieves some result.• An algorithm is a description of a process in a step-by-step manner. • The same algorithm could be written in many languages.
![Page 3: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/3.jpg)
![Page 4: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/4.jpg)
![Page 5: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/5.jpg)
![Page 6: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/6.jpg)
Python
• The programming language we will be using is called Python• http://www.python.org
• Python is a popular programing language, which is designed to be easy to read.• Used by many companies.
• It’s used by companies like Google, Industrial Light & Magic, Pixar, Nextel, and others
• Also used to make application software flexible and expendable.• For example, can be used to program GIMP or Blender
![Page 7: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/7.jpg)
or newer
![Page 8: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/8.jpg)
![Page 9: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/9.jpg)
![Page 10: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/10.jpg)
![Page 11: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/11.jpg)
![Page 12: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/12.jpg)
![Page 13: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/13.jpg)
![Page 14: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/14.jpg)
Key Words, Operators, and Syntax: an Overview
• Key words: predefined words used to write program in high-level language• Each key word has specific meaning
• Operators: perform operations on data• Example: math operators to perform arithmetic
• Syntax: set of rules to be followed when writing program• Statement: individual instruction used in high-level
language
![Page 15: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/15.jpg)
Compilers and Interpreters
• Programs written in high-level languages such as Python must be translated into machine language to be executed• Compiler: translates high-level language program into separate
machine language program• Machine language program can be executed at any time
![Page 16: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/16.jpg)
Compilers and Interpreters (cont’d.)
• Interpreter: translates and executes instructions in high-level language program• Used by Python language• Interprets one instruction at a time• No separate machine language program
• Source code: statements written by programmer• Syntax error: prevents code from being translated
![Page 17: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/17.jpg)
Compilers and Interpreters (cont’d.)
![Page 18: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/18.jpg)
Using Python
• Python must be installed and configured prior to use• One of the items installed is the Python interpreter
• Python interpreter can be used in two modes:• Interactive mode: enter statements on keyboard• Script mode: save statements in Python script
![Page 19: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/19.jpg)
Interactive Mode
• When you start Python in interactive mode, you will see a prompt• Indicates the interpreter is waiting for a Python statement to be typed• Prompt reappears after previous statement is executed• Error message displayed If you incorrectly type a statement
• Good way to learn new parts of Python
![Page 20: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/20.jpg)
Writing Python Programs and Running Them in Script Mode
• Statements entered in interactive mode are not saved as a program• To have a program use script mode• Save a set of Python statements in a file• The filename should have the .py extension• To run the file, or script, type python filename at the operating system command line
![Page 21: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/21.jpg)
The IDLE Programming Environment
• IDLE (Integrated Development Program): single program that provides tools to write, execute and test a program• Automatically installed when Python language is installed• Runs in interactive mode• Has built-in text editor with features designed to help write Python programs
![Page 22: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/22.jpg)
![Page 23: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/23.jpg)
![Page 24: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/24.jpg)
![Page 25: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/25.jpg)
![Page 26: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/26.jpg)
![Page 27: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/27.jpg)
![Page 28: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/28.jpg)
![Page 29: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/29.jpg)
![Page 30: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/30.jpg)
![Page 31: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/31.jpg)
![Page 32: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/32.jpg)
![Page 33: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/33.jpg)
![Page 34: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/34.jpg)
![Page 35: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/35.jpg)
![Page 36: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/36.jpg)
![Page 37: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/37.jpg)
![Page 38: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/38.jpg)
![Page 39: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/39.jpg)
![Page 40: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/40.jpg)
![Page 41: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/41.jpg)
![Page 42: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/42.jpg)
![Page 43: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/43.jpg)
![Page 44: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/44.jpg)
![Page 45: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/45.jpg)
![Page 46: CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697c0201a28abf838cd27dd/html5/thumbnails/46.jpg)