CSC108H1 Midterm: UTSG CSC 108 20099_t1_solution

113 views5 pages
7 Mar 2019
School
Course
Professor
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Suppose these functions have been de ned: import media def do_something(left, right): left = right for pixel in left: media. set_red(pixel, 0) def do_stuff(a, b, c): a = b + c c = a + b return a. Solution: a = 145 one = 20 two = 25 one = do_stuff(a, one, two) print a output: 145 print one output: 45 print two output: 25 pic1 = media. load_picture(media. choose_file()) pic2 = media. load_picture(media. choose_file()) do_something(pic1, pic2) media. show(pic1) Strictly speaking, the answer for pic1 should be yes, unless the picture had no red in it to begin with. You will need to use one variable for the parameter and one variable for the pixel values in the for loop. You can earn the full 6 marks if you use only one more variable. If you use more than one, you can earn at most 5 marks. def rotate_rgb(pic): for p in pic: red = media. get_red(p) media. set_red(p, media. get_green(p)) media. set_green(p, media. get_blue(p)) media. set_blue(p, red)