Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture # 27 Python I. Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a.

Similar presentations


Presentation on theme: "Lecture # 27 Python I. Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a."— Presentation transcript:

1 Lecture # 27 Python I

2 Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a serious web programming language used by Google, ILM, etc.

3 Jython Jython is a “dialect” of Python Python is implemented in C Jython is implemented in Java We use JES JES = Jython Environment for Students

4 Downloading Jython http://code.google.com/p/mediacomp-jes/ http://code.google.com/p/mediacomp- jes/downloads/list

5 Using Jython Select JES from “Programs” Click on the black part of the UI after the command prompt >>>

6 Jython DEMO print 5 + 9 print “Hello” x = 5 + 9 print x message = “Hello There” print message

7 Jython DEMO print 5 + 9 print “Hello” x = 5 + 9 print x message = “Hello There” print message Note: Python is case sensitive. “Print” and “Message” won’t work.

8 Jython DEMO Pictures pickAFile()

9 Jython DEMO Pictures pickAFile() print pickAFile()

10 Jython DEMO Pictures pickAFile() print pickAFile() file = pickAFile()

11 Jython DEMO Pictures pickAFile() print pickAFile() file = pickAFile() print file

12 Jython DEMO Pictures pickAFile() print pickAFile() file = pickAFile() print file pict=makePicture(file) # interpret as picture

13 Jython DEMO Pictures pickAFile() print pickAFile() file = pickAFile() print file pict=makePicture(file) # interpret as picture show(pict) # display as picture

14 How could we do this all at once?

15 show(makePicture(pickAFile()))

16 How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py

17 How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py And run it: open it and load it

18 How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py And run it: open it and load it King of the “1-liners”

19 Jython DEMO Sound file = pickAFile() print file sound=makeSound(file) # interpret as sound play(sound) # lets listen to it All together: play(makeSound(pickAFile())) Save as a Python program and run it

20 Jython Functions def myFunction(): colon

21 Jython Functions def myFunction(): colon parentheses

22 Jython Functions def myFunction(): colon parentheses function name

23 Jython Functions def myFunction(): colon parentheses function name “def” instead of “function()”

24 Jython Functions def myFunction(): colon parentheses function name “def” instead of “function()” The function must be called somewhere

25 Jython Functions def myFunction(): block of commands

26 Jython Functions def myFunction(): block of commands Note indentation!

27 Jython Functions: Indentation Indentation is critical in Python Indentation associates these commands with this function Indentation separates commands from other functions

28 Jython Function: Example def pickAndShow(): file = pickAFile() myPict = makePicture(file) show(myPict) pickAndShow()# somewhere we have to call the function


Download ppt "Lecture # 27 Python I. Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a."

Similar presentations


Ads by Google