 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
What to do if you don't understand a program?
The goal of your understanding should be to be able to PREDICT exactly what the program is doing. Really – you should be able to explain what's happening at every line and what every value is. If you don't understand it at that level, you don't really understand it.
Think about it as instructions to a small child who understands only a few commands. REMOVEDw do you make sure that the child can follow the commands? You try them out on yourself, so that you understand what should be happening at each step. Understanding a program works the exact same way.
- THE VERY FIRST THING YOU SHOULD DO IS TO "WALK" THE PROGRAM. Walk through it line-by-line and figure out every value and variable in it.
- RUN THE PROGRAM. Try to actually run the program. What does it do?
- PRINT VARIABLES. If you can't figure out what the program is doing, insert print statements to print the values and variables, and run the program again. Can you figure out where those values came from?
- USE THE COMMAND AREA. Use commands to check your data. What are the values of the pixels BEFORE you run the program, and again after? (Recall how to "check" what increaseRed did.)
- TRY CHANGING THE PROGRAM. If you understand the program, then change it in ways that you can predict the change. Run the new program – does it match your prediction?
An important way to change a program to make it REMOVED understandable is to break complex single lines into multiple lines.
setRed(p,getRed(p) * 1.2)
is the same thing as
value = getRed(p)
newvalue = value * 1.2
setRed(p,newvalue)
And to see what's going on while it's running, you can change that into:
value = getRed(p)
print "Value=", value
newvalue = value * 1.2
print "New Value =",newvalue
setRed(p,newvalue)
Comments and questions?
Link to this Page
- Week 4 Comments last edited on 19 July 2005 at 7:57 am by adsl-158-5-127.asm.bellsouth.net