Python programming

16
Python programming Introduction to the JES environment and basics of Python

description

Python programming. Introduction to the JES environment and basics of Python. Python. The programming language we will be using is called Python http://www.python.org It’s used by companies like Google, Industrial Light & Magic, Nextel, and others - PowerPoint PPT Presentation

Transcript of Python programming

Page 1: Python programming

Python programming

Introduction to the JES environment and basics of Python

Page 2: Python programming

Python

• The programming language we will be using is called Python– http://www.python.org– It’s used by companies like Google, Industrial Light &

Magic, Nextel, and others• The kind of Python we’re using is called Jython

(Java-based Python)– http://www.jython.org

• We’ll be using a specific tool to make Python programming easier, called JES (Jython Environment for Students).– http://coweb.cc.gatech.edu/mediaComp-teach/26

Page 3: Python programming

JES - Jython Environment for Students

Program Area

Command Area

Program area- A simple editor for programs

Command area- Interaction with Jython

Page 4: Python programming

>>> 5 + 38>>> ‘spam’‘spam’>>> “spam”‘spam’>>> “spam and more spam”‘spam and more spam’>>> ‘spam’ + ‘spam’‘spamspam’

Python interaction through commands

Anything you type in command area is evaluated and its value is displayed

• Example:

prompt

Page 5: Python programming

>>> print 5 + 38>>> print ‘spam’spam>>> ‘spam’ + ‘spam’‘spamspam’>>> print ‘spam’ + ‘spam’Spamspam

print displays the value of an expression

• In many cases it makes no difference whether you use print - the result gets displayed anyway.

Note: no quotes!

Page 6: Python programming

Command Area Editing

• Up/down arrows walk through command history

• You can edit the line at the bottom– Just put the cursor at the end of the line

before hitting Return/Enter.

Page 7: Python programming

Variables are names for data

Example:

a= 3

b= -1

c = 2

x = 0

f = a*x*x + b*x + c

Page 8: Python programming

Variables -more examples

• Variables of other typesnewsItem = “You’ve got spam!”

• Variables keep their value for the duration of a program or until they get a new value through a new assignment

a = 3

b = a *2 + 5

a = 0

Up to this point the value of a is still 3, but then it changes to 0

Page 9: Python programming

Types of data

• Integernum = -3

• Floating point numberanswer = 62.49

• Characterletter = ‘5’

• Stringnote = “lol jkjk”

Page 10: Python programming

Python functions

• Python has a lot of built-in functions for general mathematical manipulation, eg:

• sqrt(4) - computes the square root of 4• ord(‘A’) - computes the ASCII code for

character ‘A’ (i.e., a numeric code)• str(4) – produces a string corresponding to

a numberExample: print (-b+sqrt(b*b - 4*a*c))/2*a

Page 11: Python programming

Special JES-Python functions

• JES defines some special functions for media computation

Page 12: Python programming

Functions in general

F(a,b)

4

‘a’ F(4, ‘a’)

side-effects

Page 13: Python programming

Example: sqrt()

sqrt(a)4 2

side-effects

Page 14: Python programming

Example: showInformation()

showInformation(message)message

Pops up a new window displaying the message text

showInformation(message):message: the message to show to the userOpens a message dialog to the user showing information

Page 15: Python programming

Exploring more functions

• The JES Functions menu has functions arranged by type - check them out!

• Can you find a function that inputs a number?

• Can you find under what category pickAFile() is listed?

Page 16: Python programming

Reading

• Chapters 1, and Sections 2.1-2.4 from “Introduction to Computing and Programming in Python” (up to page 22)