Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Today’s Topics Questions/comments? Backslashes Review of if/else and while Tracing All the JES image functions covered in pages 39-60 Write a few more functions

3 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Backslashes Backslashes in strings are special because they are used as the first character in an “escape sequence” \\ \' \" \a bell \b backspace \f formfeed \n newline \r carriage return \t tab

4 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Backslashes Usage: Say you wanted double quotes to be part of a string and you were using double quotes around the string. eg. sentence = "CS102 is a "great" class." Anybody have any guesses as why this would be a problem?

5 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Backslashes Now the double quotes around great are part of the string. sentence = "CS102 is a \"great\" class." Similarly if you wanted to use single quotes within a string denoted by single quotes: anotherSentence = 'The password is 'python'.' # bad anotherSentence = 'The password is \'python\'.' # good

6 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Reminder of if/else and while First I want to remind you of two constructs if and while on the board.

7 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Tracing a program Our text mentions that “The most important skill is tracing”. Anyone recall what that means?

8 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Tracing a program Tracing means following the code of the program, line-by-line and figuring out exactly what it does. You should keep track of variables and their values as you trace through code. Let's trace through a function I wrote this morning to try to figure out what it does.

9 Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Some JES image functions makePicture getWidth, getHeight getPixel getPixels getX, getY getRed, getBlue, getGreen setRed, setBlue, setGreen distance getColor, setColor, makeColor pickAColor makeLighter, makeDarker writePictureTo show

10 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 / 09 / 2009 Instructor: Michael Eckmann."

Similar presentations


Ads by Google