CIS 465 Multimedia
CIS 465 Multimedia
JES (Jython Environment for Students) Tutorial -- I
General Guide to Using JES 3
More info on Python:
JES Screen:
[pic]
JES interface has 2 main areas:
• the Program Area (top part) –
o write your Jython programs here
o provides a text editor
o after typing in your program, go to File > Save Program As, using a filename with extension .py (for Python) – on my version of JES (3.0.6), a window opened up displaying the file structure under My Documents on the computer—however, you can save it anywhere
• the Command Area (bottom part)
o can type in Jython/Python commands here at the “>>>” prompt, hit Enter
o can type in names of loaded programs to be run
o commands are interpreted by Jython interpreter
Note:
Load Program Button
>>>>> IMPORTANT! >> word[-100:]
'HelpA'
>>> word[-10] # error
Traceback (most recent call last):
File "", line 1, in ?
IndexError: string index out of range
E.g.s
>>> s = "Lalapalooza"
>>> print s.count("la")
1
>>> print s.find("L") ( Note: chars in a string start at index 0!
0
>>> print s.find("pal")
4
>>> print s.rfind("zoo") ( not found
-1
>>> print s.rfind("La")
0
>>> s = "123anywhERE"
>>> print s
123anywhERE
>>> s.isdigit()
0
>>> s.isalpha()
0
>>> s = "OK"
>>> print s.isalpha()
1
>>> s = "Roses are red Violets are yellow"
>>> s.split(" ")
['Roses', 'are', 'red', 'Violets', 'are', 'yellow']
Programming Constructs in Python
Note:
Comment using “#”.
Some examples:
# this is the first comment
SPAM = 1 # and this is the second comment
# ... and now a third!
STRING = "# This is not a comment."
1. Looping
a. for command
• uses an index variable, the keyword “in” and a list
• note use of colon after the list – it signals that what comes next is a block
• commands in a block must be indented at least 2 spaces to become part of the block
E.g.
[pic]
>>> myloopa()
1
2
3
• can use range() function to generate the list
1. one arg: range(3) → range is from 0 to arg-1
2. two args; range(1,4) → range starts at 1 ends at 3
3. three args; range(1,4,2) →starts with 1, steps of 2, ends at 3
E.g.
[pic]
>>> myloopc()
0
1
***
1
2
***
1
3
5
***
1
>>>
• can use an array for the list
E.g.
for sample in getSamples(mySound):
b. while command
• takes a logical expression and executes its block as long as the logical expression is true
• note use of colon after the list after logical expression
E.g.
[pic]
>>> mywhile()
1
2
3
4
2. Selection (branching)
a. if command
• else is optional
• can nest the if commands
E.g. 1 – no else part
[pic]
>>> myifa()
Good grade
E.g. 2 – else part present
[pic]
>>> myifb()
Could be ok, we'll see
E.g. 3 – Nested if/else
[pic]
>>> myifc()
68 :should be improved
E.g. 4
Note:
• true or false task could be more than one statement
• indentation determines in what block a statement is
[pic]
>>> myifd()
75 :is OK
75 :could be any grade < 80
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.