TOPIC Introduction to Python 1 Python A programming

  • Slides: 17
Download presentation
TOPIC: Introduction to Python 1

TOPIC: Introduction to Python 1

Python – A programming language • Python is one several available computer programming languages

Python – A programming language • Python is one several available computer programming languages for developing software. • Programming languages evolved to accommodate various instruction format. Some languages are more English while other rely on more scientific notation COBOL: Python: Add 1 to total = total + 1 • Language may also be more suitable for different platforms such as the web, mobile devices or small robots. Introduction to Python 2

Python – A programming language • Our use of Python will focus on the

Python – A programming language • Our use of Python will focus on the language’s simplicity to do small projects • While a basic language, Python is widely used in the industry including: Ø The game Civilization 4 has all its inner logic, including AI, implemented in Python. Ø NASA extensively uses the language Ø Many data science applications make use of Python libraries • Python is also helpful to introduce concepts that will be expanded in future courses that will focus on the Java language. Introduction to Python 3

Developing Python Software • Virtually all computer languages have a tool that enables you

Developing Python Software • Virtually all computer languages have a tool that enables you to write instructions in the language and execute instructions. • These tools are referred to as an Integrated Development Environment (IDE). • The IDE for Python is the IDLE integrated development environment for Python 3. 6. Other IDEs you may have heard of are : Eclipse(Java), Visual Studio(C#) and Android Studio (Android applications) Introduction to Python 4

Download IDLE and Python https: //www. python. org/ downloads/ Introduction to Python 5

Download IDLE and Python https: //www. python. org/ downloads/ Introduction to Python 5

IDLE A quick way to launch IDLE is from Window’s Start Menu choose IDLE

IDLE A quick way to launch IDLE is from Window’s Start Menu choose IDLE (Python GUI) • If you use Windows 10, see the example • For Windows 7 or Vista see the example in the How. To. Start. IDLE. pdf tutorial Introduction to Python 6

IDLE Shell Try as statement in the IDLE Shell: Put the statement that you

IDLE Shell Try as statement in the IDLE Shell: Put the statement that you want to be displayed on the screen in double quotes. This is a String type that we will discuss later. Introduction to Python 7

Working within the Shell >>>help() command starts interactive help Ctrl-C command exits interactive help

Working within the Shell >>>help() command starts interactive help Ctrl-C command exits interactive help Interactive help for the if operator Introduction to Python 8

Creating and Running a Python program To create a new Python program, choose File

Creating and Running a Python program To create a new Python program, choose File New File to open a text editor window A new window will be open for editing To save do File Save as To run do Run module or click F 5 Introduction to Python 9

Saving file If the file that you try to run does not have all

Saving file If the file that you try to run does not have all the recent updates you will see the following window. Click OK, follow the prompt and save your work Introduction to Python 10

Using Pathway 2 Code and Python The Pathway 2 Code instructions can be downloaded

Using Pathway 2 Code and Python The Pathway 2 Code instructions can be downloaded into your Python environment and executed within IDLE And Python This process takes 2 steps: Ø Download the Pathway 2 Code python library – this software allows Pathway 2 Code commands such as Fill. Circle to execute in Python. Ø Download your Pathway 2 Code instruction set as a Python program • Make sure you store the Python module and your instruction set in the same directory • You only need to download the module once, it can be used within all your instruction sets in that directory Introduction to Python 11

Executing your Pathway 2 Code instructions in Python • After downloading your instruction set

Executing your Pathway 2 Code instructions in Python • After downloading your instruction set and Pathway 2 Code Python module, open your instruction set in IDLE and Run ! • You may notice some additional instructions, such as import. These instructions link your Python program with the Pathway 2 Code module. Introduction to Python 12

Executing your Pathway 2 Code instructions in Python - OUTPUT • You likely see

Executing your Pathway 2 Code instructions in Python - OUTPUT • You likely see 3 windows: Ø Your Python code in IDLE Ø Python shell showing nongraphical output Ø Graphic window show results of graphical commands • You can now make instruction changes in Python. You do not need to go back to your original Pathway 2 Code instruction set • Editing in IDLE however will not give you prompts for available commands and associated parameters as when using Pathway 2 Code. Introduction to Python 13

Python Program Comments • Comments improve code readability and documentation • Comments are not

Python Program Comments • Comments improve code readability and documentation • Comments are not executed by a computer (a compiler skips them): Ø Comments are for programmers and users Ø Comments are not for computers Introduction to Python 14

Comments Syntax • Start comments with # – the rest of line is ignored.

Comments Syntax • Start comments with # – the rest of line is ignored. • Can include a “documentation string” as the first line of any new function or class that you define. • The development environment, debugger, and other tools use it: it’s good style to document your code with comments. Introduction to Python 15

Multiline Comments # this is a single line comment # This a second line

Multiline Comments # this is a single line comment # This a second line of comments print ("trying out some comments") """and here. . I hate Python Nah, just kidding. . . is a multi-line comment""" print("Python is the best") Introduction to Python 16

Using Python Shell as a Calculator Introduction to Python 17

Using Python Shell as a Calculator Introduction to Python 17