Alternative Range Function


Python's built in range function is designed to be used in conjunction with 0-based indexing. (Documentation for range is available on the web.) Since the designers of JES made the decision to use 1-based indexing for images and sounds, it will be convenient for us to use an alternative to the built in range function called range1. Here is the code for our alternative implementation:


#range1 - Alternative to built in range function for 1 based indexing.
#The default starting point is 1 rather than 0. 
#The ending point is increased by 1 relative the the built in range function.
#Examples: 
#>>>range1(2)       #returns [1, 2]
#>>>range1(2, 4)     #returns [2, 3, 4]
#>>>range1(2, 6, 2) #returns [2, 4, 6]
#Nathan Sprague 1/16/09

def range1(*args):
  if len(args) == 1:
    return range(1,args[0] + 1)
  if len(args) == 2:
    return range(args[0], args[1] + 1)
  if len(args) == 3:
    return range(args[0], args[1] + 1, args[2])
You can make use of this function by copying and pasting it into your .py file.

New Versions of JES

If you are running JES on your own computer, you can download one of the following updated versions that include range1 as a built in function: