home—info—lects—labs—exams—hws
—D2L—breeze (snow day)—tutor/PIs
lab04-calling-picture-functions
Calling a function
doubles; 'argument', 'return type'
On the quiz, we saw example of things like (2n+1)²,
where we take the result of one operation (doubling and adding one),
and use that as an input to another operation (squaring).
(In general, this is “function composition” — f(g(n)), if you want to
impress your friends.)
Using one function's result as input to another function is actually common.
As a class, let's discuss:
-
sqrt( len("hello")*2 )
-
chr( ord('A') )
-
ord('E') - ord('A')
-
chr( ord('A') + 5 )
-
alphaStart = ord('A')-1
chr( alphaStart+26 )
|
-
pow(26, len("hello"))
Yesterday, we mentioned some file and picture-handling functions like pickAFile,
makePicture, and show.
Below, with a partner, you'll call these functions and you'll pass the result of one function to another!
Updated list:
In Python, we have several types of values:
- integers (“ints”):
e.g. 17,
9999,
-5,
0,
23423423432234234
- floating-point numbers (“double”s),
e.g. -2.34, 6.023e23, 1e9, 4.0
- characters: e.g. 'A', '+',
' ', '\n'.
- strings: e.g. "aloha", "Individual characters, strung together!"
- (picture-objects: No way to type in a picture-object directly;
they are returned by makePicture;
as text they simply displayed as a filename+width+height.)
TODO
-
On google, find and download two pictures:
one of an an aardvark, and one of a echinda.
(Take note of where you are saving the pictures on your local computer —
presumably in folder called "Downloads".)
-
Evaluate the function-call pickAFile().
(Note: this function is not a standard python function; it is provided by JES.)
What type of data are we giving to pickAFile?
What is its return-type?
-
makePicture( "C:/Users/yourUserName/Downloads/yourAardvarkImageFile" )
What type of data are we giving to makePicture?
What is its return-type?
-
makePicture( pickAFile() )
What type of data are we giving to makePicture?
What is its return-type?
-
show( makePicture( "C:/Users/yourUserName/Downloads/yourAardvarkImageFile" ) )
What type of data are we giving to show?
-
show( makePicture( pickAFile() ) )
What type of data are we giving to show?
home—info—lects—labs—exams—hws
—D2L—breeze (snow day)—tutor/PIs