Solutions for the Python Challenge

Show possible solutions for: All levels; level: previous, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, next

Possible solution for level 11

URI:
http://www.pythonchallenge.com/pc/return/5808.html
Log-in data:
Username: huge; password: file
Comment:
Possible Solution:
import Image

# download the image from: http://www.pythonchallenge.com/pc/return/cave.jpg

image = Image.open("cave.jpg")
nsize = tuple([x / 2 for x in image.size])
odd = even = Image.new(image.mode, nsize)

for x in range(image.size[0]):
    for y in range(image.size[1]):
        if x % 2 == 0 and y % 2 == 0:
            even.putpixel((x / 2, y / 2), image.getpixel((x, y)))
        elif x % 2 == 0 and y % 2 == 1:
            odd.putpixel((x / 2, (y - 1) / 2), image.getpixel((x, y)))
        elif x % 2 == 1 and y % 2 == 0:
            even.putpixel(((x - 1) / 2, y / 2), image.getpixel((x, y)))
        else:
            odd.putpixel(((x - 1) / 2, (y - 1) / 2), image.getpixel((x, y)))

even.save("even.jpg")
odd.save("odd.jpg")

(Download this source code.)

Code word for next challenge:
evil

By Holger Thölking, May 29th, 2007.