Documentation

We designed TigerJython specifically for classroom use and to help beginners with their first steps in programming. For this purpose we made some minor changes to the Python programming language as documented below.

There is also a reference for the builtin Turtle graphics available, including a gallery with examples.

The tutorials with an introductory course for Python programming and the gallery with the works of students are currently available in German only.

Differences between TigerJython and Python

Repetitions and Loops

The Python language has both a while- and a for-loop to repeat a piece of code several times. We added a third variant, using the keyword repeat followed by the number of repetitions.

The rationale behind this is that beginners often need to repeat a piece of code a given number of times. At the same time, the concept of variables, expecially those changing during a loop, is rather difficult. Using our new repeat-statement, you can now create a loop without using any variables.

Input and Output

All user input in TigerJython is done with small dialog windows and never through a console. Thus, input will always open a small window and prompt the user to enter something. We also added the functions inputInt and inputFloat to request an integer or (floating point) number.

In addition to the input- and print-statements, there is also a msgDlg-function which will output the given values using a small dialog window.

In Python 2, the input function input will try and evaluate the given user input as a Python expression. This is hardly suited for beginners who want to ask the user for, say, a name. We therefore changed the input-Function so that it does not evaluate the given input, but converts it to an integer, float or string, respectively.

Additional functions

We included a few additional built-in functions to help you create your programs more quickly. They are primarily intended for educational use and are not available in other Python distributions.

makeColor(color-value)

Create a java.awt.Color-object. As an argument you can give a string with a html/web color such as "Aquamarine" or "#7FFFD4" (we internally use the list as found on: Wikipedia: color names). You could also specify the color value as an integer value or give three floating point values between 0.0 and 1.0 for the three components red, green and blue, respectively.

makeColor("#7FFFD4")
makeColor("Aqua-Marine")  # Case and word-separation does not matter!
makeColor(0x7FFFD4)
makeColor(8388564)
makeColor(0.5, 1.0, 0.83)
makeColor(128, 255, 212)

We also provide the possibility to get a color from the rainbow's spectrum, ranging from 0.0 to 1.0:

makeColor("rainbow", 0.38)
playTone(frequency)

Play a 'sine-wave' sound with the given frequency. This is, of course, a very crude method of generating sounds, reminiscent of the old PC-loudspeakers. In addition to the frequency you can use one or both of the two keyword arguments duration and volume. Both require an integer where duration is measured in milliseconds and the volume in percentage (ranging from 0 to 100).

If you want to play a simple melody, you can also give a list with frequencies to play. In this case, the values for duration and volume apply to all given values.

playTone(440.0)
playTone(440, duration=500)
playTone(440, duration=500, volume=75)
playTone([440, 360], duration=200)

In addition to playing a certain frequency, you can also play a soundeffect from the list of "bird", "seashore", "gunshot", "telephone":

playTone("bird")

Finally, there is also the possibility to use the MIDI-synthesizer, albeit in a limited fashion (use a dedicated library for more sophisticated features). To use the MIDI-synthesizer you have to specify an instrument as well as a melody. The latter can be given as a string or as a list where each note is tupled with a duration in milliseconds.

playTone("ccggaag", instrument="piano")
playTone([("a", 400), ("g", 200), ("f", 600), ("c", 400)], instrument=50)

The instrument can either be an integer for the MIDI-preset or one of the following predefined values: "piano", "xylophone", "organ", "guitar", "violin", "strings", "harp", "trumpet", "sax", "oboe", "flute".

playTone has also a sister-function startTone with the same arguments and functionality. However, startTone will not wait for the sounds to have played but return control to the program immediately. This allows you to have some simple background music or sounds.

In case you are interested in playing some advanced music, check out Music with Jython/JEM.

head(list), tail(list)

head returns the first element of a list and tail returns the rest, that is everything except for the first element. This allows for some simple list access without having to use an index.

myList = [2, 3, 5, 7]
head(myList)   # 2
tail(myList)   # [3, 5, 7]
indices(list|string|tuple)

indices returns an XRange-object with the indices for the given list-like object. It is equivalent to xrange(len(L)).

A variant of indices accepts two list-like objects and returns an XRange-object with all indices found in both objects. The Python-equivalent is: xrange(min(len(L_1), len(L_2))).

myList = [2, 3, 5, 7]
for i in indices(myList):
    print str(i) + ". item = " + str(myList[i])