CS 0007: Fall 2009 Lab 1 YOUR NAME: YOUR PARTNER'S NAME: To get credit on this lab, attend recitation 9/4, work with your partner to answer the questions, and give "reasonable" (if not all correct) answers. Each of you should hand in a hardcopy of your own solution, due 9/11 at the beginning of your recitation. ********************************************************************** *********Part 1: On-line materials ********************************************************************** Find the course web page: You can remember/bookmark the link: www.cs.pitt.edu/~wiebe/courses/CS0007/Fall09 If you ever forget it, go to the CS Department webpage, look up Prof Wiebe's home page; you'll find the link there on the front. If you have any questions about installing the code, using CodeLab, finding the courseweb forum, etc., please ask. ********************************************************************** *********Part 2: Tracing ********************************************************************** Now for the fun part of the lab! To begin, download the python programs stored on the course schedule under today's lab. Recall from lecture that WING allows us to trace programs step by step, and examine the values of the variables as the program executes. You'll now do this with numbers.py ***Open Wing, and do the following: (a) ***Open numbers.py (b) There are different ways to start the debugging process. In lecture, we set a breakpoint next to the first line of code, and then hit the debug button. A simpler way is to just click "Step Into" once - this starts the debugging process as well. So, *** click "Step Into" once. Find the "Stack Data" window, which shows the values of the variables. For now you can ignore names that are surrounded by underscores (__). ***Now use "Step Over" or "Step Into" to trace the program step by step. (For this simple program there is no difference between them.) Make sure you understand what you are seeing in the "Stack Data" window. If you do not, please ask! (c) Now, let's do a more interesting program. ***SWITCH PLACES WITH YOUR PARTNER (to give him or her a chance at the keyboard) ***Open lab1_trace.py. **RUN the program using the RUN button, so you can see what it does. You will use "Step Over" rather than "Step Into" to trace this program. "Step Over" will execute the next statement and show the updates to the variables. But, it won't step down into the functions and show their internal workings. !!HINT!! if you need to start over, hit the STOP button. As you step through the program, talk to your partner and try to figure out what is going on. !!HINT!! You can use the python shell for help. E.g., Doing the following will help you understand the program: >> import media >> import random >> help(media.create_picture) >> help(random.randint) !!HINT!! help(media) prints out a lot of stuff. The stuff it prints are the RGB values of the colors. !!NOTE!! "pic" holds an object of type "picture.Picture"; pix holds an object of type "pixel.Pixel"; "new_color" holds an object of type "color.Color". These types are defined in the "media" module (actually, modules it imports). You don't need to know anything else about them in order to use the functions in the "media" module! Values of the listed vars after each line has executed pic = media.create_picture(100, 100) # What color is the new picture? x = random.randint(0, 99) x: y = random.randint(0, 99) y: pix = media.get_pixel(pic, x, y) red = media.get_red(pix) red: green = media.get_green(pix) green: blue = media.get_blue(pix) blue: # Why do red, green, and blue # have these values? new_color = media.orange media.add_rect_filled(pic, x, y, 10, 10, new_color) media.show(pic) new_red = media.get_red(pix) new_red: new_green = media.get_green(pix) new_green: new_blue = media.get_blue(pix) new_blue: # Why do new_red, new_green, and # new_blue have these values? ********************************************************************** *********Part 3: Writing Some of Your Own Code ********************************************************************** *** SWITCH PLACES AGAIN (a) *** Open and run lab1.py (b) *** In the shell, call function "get_picture()" and store the value returns in a variable called "pic". *** Display the picture by calling "media.show(pic)" (c) *** Call function "maximize_red" with "pic" as an argument. Call "media.show(pic)" to see the modified picture. Make sure you understand the program. Next time in lab: you will define your own functions and add them to this program. *********Part 4: Survey questions What year are you in? Do you have a major? If your answer is 'yes': what is your major? If you answer is 'no': what majors are you considering?