Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 102 Computers In Context (Multimedia)‏ 02 / 02 / 2009 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 102 Computers In Context (Multimedia)‏ 02 / 02 / 2009 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 102 Computers In Context (Multimedia)‏ 02 / 02 / 2009 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Today’s Topics Questions/comments? Reminder of the syntax of a function definition Return statement Write some functions Docstrings

3 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Defining functions def is used to define functions –A function is defined in the following way: def myFunName(parm1, parm2, parm3): statement1 statement2 statement3 statement4 Note: all statements in the body of the function must be indented like above and functions can have 0 or more parameters (the one above has 3).

4 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 if/elif/else if statements are used to specify if something is true, execute some code otherwise execute some other code. if condition: # code here to execute if the condition is true elif condition2: # code here to execute if the condition2 is true (and # condition was false)‏ elif condition3: # code here to execute if the condition3 is true (and # condition was false and condition2 was false)‏ else: # code here to execute if all the conditions are false There was a typo in last class's notes. The else needs a semicolon as above, but the semicolon was missing in the notes of 1/30/09.

5 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Reminder of JES image functions What do the following functions take as parameters and what do they return? pickAFile makePicture show After changing pixels in an image that is already displayed onscreen, you can call repaint to have the current pixels get reloaded onto the screen. repaint takes a picture as a parameter. Let me edit the program from last class.

6 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Try these Write a function named hello that displays the text Hello, World! greetWrite a function named greet that takes in someone's name and displays a greeting to that person. For example if I call greet like this: greet('Mike')‏ –It should display Hello, Mike, nice to see you.

7 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Try these displayWrite a function named display that displays an image, given a file name as a parameter. display('boat.jpg')‏ –It should display the image boat.jpg Write a function named reduceRed which takes in an image file name and reduces the intensity of the red in the image by 30%. That is, each pixel's red channel should be multiplied by 0.7 reduceRed('boat.jpg')‏ –It should display the image boat.jpg but with less intense reds

8 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 docstrings Docstrings are special comments describing the function, module, class or method being defined. Example: def factorial(num): """ factorial computes the factorial of the number num. num! = num * (num-1) * (num-2) *... * 1 returns an integer, the factorial of num """ fact = 1 while (num > 1): fact = fact * num num -= 1 return fact


Download ppt "CS 102 Computers In Context (Multimedia)‏ 02 / 02 / 2009 Instructor: Michael Eckmann."

Similar presentations


Ads by Google