CSC108H1 Midterm: UTSG CSC 108 2009_winter_sol

39 views22 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

Complete the following function according to its docstring description. def clump(l, k): """return a list that is the same as list l, but with the items grouped into sublists of length k (except for the last sublist, which may be shorter). k must be >= 1. Example: clump([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4) returns the list. Solution: ans = [] subpart = [] for i in range(len(l)): subpart. append(l[i]) if i % k == k - 1: ans. append(subpart) subpart = [] if subpart != []: ans. append(subpart) return ans. Complete the following function according to its docstring description. Hint: media. get_pixel lets you get the pixel at desired coordinates from a picture. You can then either get or set the pixel"s colour. def cutout(p1, p2, x, y, h, w): The rectangle to change has its upper-left corner at pixel (x, y), and has height h and width w. Solution: def cutout(p1, p2, x, y, h, w):

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents