Basics of using the JES Window

The top part is the program area. This where you write your recipes: The programs and their names that you’re creating. This area is simply a text editor—think of it as Microsoft Word for your programs. The computer doesn’t actually try to interpret the names that you type up in the program area until you press the Load, and you can’t press the Load button until you’ve saved your program

The bottom part is the command area. This is where you command the computer to do something. You type your commands at the >>> prompt, and when you hit return, the computer will interpret your words (i.e., apply the meanings and encodings of the Python programming language) and do what you have told it to do. This interpretation will include whatever you typed and loaded from the program area as well.

Get to know your Help! An important feature to already start exploring is the Help menu. There is a lot of great help for programming and for using JES available under that menu.

Print Command

Try typing

print 34 + 56

into the command area, then press Enter

Jython will do the calculation and then output the result.    

Try each of these:

 

 

 Types

Python takes data types seriously. If it sees you using integers, it thinks you want an integer result from your expressions. If it sees you use floating point numbers, it thinks you want a floating point result.

Try putting in

print 1.0/2.0

Now try

print 1/2

1/2 is 0? Well, why not? 1 and 2 are integers. There is no integer equal to 1/2, so the answer must be 0! Simply by adding “.0” to an integer convinces Python that we’re talking about floating point numbers, so the result will be in floating point form.


Variables

You can use variables to store information to reuse later.  Think of a variable as a container for information.  What is in the variable can change, but the name of the variable stays the same.

 
 You put something in a variable using an assignment statement.  So let's say I have a variable (container) called myLunchBox.

myLunchbox = vegemiteSandwich

would read as myLunchBox is assigned (given) the value vegemiteSandwich (I have a vegemite sandwich in my lunchbox NOT myLunchBox equals a vegemiteSandwich)

If I asked for the value of the variable myLunchBox, I would be given vegemiteSandwich.

If my next command was   myLunchBox = hamSandwich, then myLunchBox would have the new value hamSandwich.  vegemiteSandwich would now be gone. (It has been overwritten by hamSandwich.)

 

Variable Examples

Try typing the following into the Command area:

myNumber = 8

print myNumber

myNumber = 8 * 12

print myNumber

Here's another example using Strings

        myName = "Mary " + "Smith"

        print myName

Using the Program Area

I can write a 'recipe' for a function in the program area, then reuse it later.  To define (or name) a 'recipe' you use def followed by three things:

  1. The name of the recipe (function)
  2. Any inputs to it in parenthesis (or leave empty parentheses)
  3. A colon :

Here is an example:

In the program (top) area, type the following

def myDetails():

    myName = "Mary"

    myAge = "21"

    print "My name is " + myName

    print "My age is " + myAge

Often you will have more than one function defined.  Python works out which commands belong to which function by the indentations, thus it is vital that you indent your code properly.

You can even define one function inside another, provided you indent it all properly.

In the command window of JES, you can now type myDetails() and your program will run.