Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called: def bars(pic): which makes every 20 th column and row i

ID: 3550097 • Letter: W

Question

Write a function called:

def bars(pic):

which makes every 20th column and row in pic black. Do not return a picture. The function can be used with any picture. Here is the result of running bars with the caterpillar:


Write a function called:

def shuffle(pic):


which moves the first two thirds of a picture to the right. The last third of the picture is moved to the far left. Do not return a picture. The function can be used with any picture. Here is the result of running shuffle with the caterpillar:


Write a function called: def bars(pic): which makes every 20th column and row in pic black. Do not return a picture. The function can be used with any picture. Here is the result of running bars with the caterpillar: Write a function called: def shuffle(pic): which moves the first two thirds of a picture to the right. The last third of the picture is moved to the far left. Do not return a picture. The function can be used with any picture. Here is the result of running shuffle with the caterpillar:

Explanation / Answer

import Image

def bars(pic):

im = Image.open(pic)

xsize,ysize = im.size


for i in range(0,xsize,20):

for j in range(ysize):

im.putpixel((i,j),(0,0,0))


for i in range(0,ysize,20):

for j in range(xsize):

im.putpixel((j,i),(0,0,0))

im.save(pic)

def shuffle(pic):

im = Image.open(pic)

width, height = im.size

box1 = (0,0,2*width/3,height)

box2 = (2*width/3,0,width,height)


region1 = im.crop(box1)

region2 = im.crop(box2)

im.paste(region1, (width/3,0,width,height))

im.paste(region2, (0,0,width/3,height))

im.save(pic)


If you have any questions, please let us know in the comments

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote