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

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs

exam02-functions-known
Functions we've used


#### numeric functions # 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. # min( 7.0, 2.0 ) ⇒ 2.0 # 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"
#### 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

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.Apr.08 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme