RU beehive logo ITEC dept promo banner
ITEC 109
2014spring
ibarland

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs

functions-used
Syntax and Functions cheat-sheet

Clickable Index:


Syntax


Function summaries

#### numeric functions

# sqrt : float → float
# Return the square root of a given number.
#
sqrt( 25.0 ) ⇒ 5.0
 
# pow : float, float → float
# Return one number raised to another.
#
pow( 2.0, 5.0 )  ⇒ 32.0

# max: float, float → float
# return the larger of two given numbers.
#
max( 7.0, 2.0 ) ⇒ 7.0

# min: float, float → float
# return the smaller of two given numbers.
#
max( 7.0, 2.0 ) ⇒ 2.0


# random.randrange : int → int
# Return a random natural number less than the given input.
#
random.randRange(5) ⇒ 3
random.randRange(5) ⇒ 0
random.randRange(5) ⇒ 4


# int : float1 → int
# Convert a float to an int:
#
int(  4.9 ) ⇒ 4
int( 15.0 ) ⇒ 15
int( -2.3 ) ⇒ -2



#### string functions # str : float2 → string # Convert a given number to a string # str(15) ⇒ "15" # len : string → int # Return the number of characters in a given string. # len("hello") ⇒ 5 # substring : string, int, int → string # Given some text, a start-index, and a stop-index, # return the characters of `txt` from `start` up until (but not including) `stop`. # Indices are 0-based. # substring( "radford", 3, 6) ⇒ "for" substring( "radford", 0, 3) ⇒ "rad" # string.upper : string → string # Return an upper-case version of a given string. # string.upper( "hello" ) ⇒ "HELLO" # string.capitalize : string → string # Return a capitalized version of a given string. # string.upper( "hello" ) ⇒ "Hello"
#### File, Picture, Pixel functions # pickAFile : None → string # Return a filename as selected by the meatbag sitting at the keyboard. # pickAFile() ⇒ "C:/Users/CarnieTote/Documents/important file.docx" pickAFile() ⇒ "C:/Users/CarnieTote/Documents/itec109/ufo.png" # makePicture : string -> Picture # Return a picture-object created from the provided filename. # makePicture( "ufo.png" ) ⇒ A picture with width 192 and height 47. # show : Picture → None # Display a Picture-object in a window on the screen. # show( makePicture("ufo.png") ) ⇒ None # repaint : Picture → None # Update the window where the indicated Picture-object has been previously displayed. # Useful if any pixels have been modified since. # repaint( makePicture("ufo.png") ) ⇒ None # explore : Picture → None # Pull up a pixel-explorer tool for the indicated Picture-object. # explore( makePicture("ufo.png") ) ⇒ None # getPixelAt : Picture, int, int → Pixel # Return the individual pixel object at the specified (x,y) coordinates of the given Picture-object. # getPixelAt(makePicture("ufo.png"), 5, 5) ⇒ a Pixel with color=(255,255,0) # getRed : Pixel → int # getGreen : Pixel → int # getBlue : Pixel → int # Return a value in [0,256) — the redness/greenness/blueness of the given pixel. # getGreen( getPixelAt(makePicture("ufo.png"), 5, 5) ) ⇒ 255 # setRed : Pixel, int → None # setGreen : Pixel, int → None # setBlue : Pixel, int → None # Change a pixel's red/green/blue to be the given number. # setBlue( getPixelAt(makePicture("ufo.png"), 5, 5), 22 ) ⇒ None
#### Turtle Functions # makeWorld : int, int → World # Return a World-object (a turtle-sandbox) of the given width & height. # makeWorld(20,30) ⇒ a 20-by-30 world with no turtles in it # makeTurtle : World → Turtle # Return a new turtle located at the center of the given world, facing north. # makeTurtle(makeWorld(20,30)) ⇒ a turtle at 0,0 facing 0.0 # forward : Turtle, float → None # Move the indicated turtle forward the indicated number of pixels. # turn : Turtle, float → None # Rotate the indicated turtle the indicated number of degrees clockwise. # turn( makeTurtle(makeWorld(20,30)), 90 )

1Actually, int is more versatile: It will also convert strings to ints, e.g. int("+000473") ⇒ 473.      

2 Actually, str is more versatile: It will convert both ints and floats to strings, e.g. str(15) ⇒ "15" and str(sqrt(225.0)) ⇒ "15.0". And actually, it's more versatile yet: it converts anything to a string, e.g. str( makeWorld(20,30) ) ⇒ "A 20 by 30 world with 0 turtles in it." and str( range(3) ) ⇒ "[0, 1, 2]". If a programmer ever creates a new type (like World or Turtle or Picture), they must also specify how str works for their new type.      

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs


©2014, Ian Barland, Radford University
Last modified 2014.May.05 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme