det solve_mysteryltilename: Solve the mystery as described in the handout.com # SimpleImage boilerplate provided as a starting point width = 10 # correct values needed here height = 10 SEMA image = SimpleImage.blank(width, height), for y in range( image.height): for x in range(inage.width): pixel - Inage.get_pixel(x, y) # use pixel. red etc. in here def. parse_file(filename): 92 93 Given filename, parse out and return a list of all that file's int values. (test provided) >>> parse_file('3lines.txt') (800, 600, 64, 63, 61, 60, 74, 81, 55, 56) 94 95 96 nlist = 0) with open(filename, 'r') as f: for line in f: nlist.extend( parse_line(line)) return nlist e. solve_mystery() Parse all the numbers from the given filename. Figure out the width and height of the desired image. The code to create a blank image and loop over it is the same as in week 2 - it's included in the starter file. Starter code in solve_mystery(): width = ??? # determine proper width and height values height = ??? image - SimpleImage.blank (width, height) for y in range(image. height): for x in range(image.width): pixel = image.get_pixel(x, y) # use pixel.red etc. in here # This displays image on screen image.show() Edit this code to set the pixel.red etc. of every pixel in the image using the parsed out values, using the provide range/y/x loops. This is a bit of a code puzzle. The range/y/x loops are going over the 2-d image. Each time through that loop, you want to grab the right parsed value. Think about which value you want the first time the loop runs, the second time, the third time, etc. to work out a pattern. The provided main() is set up to call your solve mystery() function when there is just 1 command line argument, like this: $ python3 parse-mystery.py 480k.txt Grayscale Pixels The following fact is needed for this puzzle: For each pixel in a grayscale image, the red, green, and blue values in each pixel must be equal. So for example a pixel might have red-50 green=50 blue=50 to be dark gray, or red=212 green=212 blue=212 to be light gray. Mystery Data The mystery campus object lives among the trees belbw lake Lagunita. It is somehow described in the file "480k.txt" which contains 480002 ints. The beginning of the list of ints looks like this (this is just the list your parse_file() returns): [800, 600, 64, 63, 61, 60, 74, 81, 55,... What could these 480002 numbers represent? It's a grayscale image! The first number is the width. The second number is the height. The remaining 480000 (800 * 600 - 480000) numbers are the grayscale values, one number per pixel. The pixel values are laid out in the 1-dimensional list. After the width and height are all the values of the top y 0 row, then all the values for y-1, then all the values for y 2 and so on in 1 big list: [width, height, y=0x=0, y=0x=1, y=0x-2, .... y=0x=799, y=1x=0, y=1x-2, y=1x=3 ... y=599x=799) This ordering of the pixels is the same, standard order that the range/y/x loops visit the pixels of an image. parse line(s): Given a string s, parse the ints out of it and retum them as a list of int values. >>> parse linel '12x76$'). (12, 67) >parse linel '800!)1764b006$ (46$*#632*16$+06$25') 1800, 600, 64, 63, 61, 60) Ist = search = while True: begin = search while begin len(s): break end - begin + 1 while end >> extract_nun( 'xx123$', 2, 5) 321 >>>> extract_nun( '176^', 2, 5) -1 if begin >= len(s): return -1 if end > len(s): return -1 s: if end >> parse_file('3lines.txt') (800, 600, 64, 63, 61, 60, 74, 81, 55, 56) 94 95 96 nlist = 0) with open(filename, 'r') as f: for line in f: nlist.extend( parse_line(line)) return nlist e. solve_mystery() Parse all the numbers from the given filename. Figure out the width and height of the desired image. The code to create a blank image and loop over it is the same as in week 2 - it's included in the starter file. Starter code in solve_mystery(): width = ??? # determine proper width and height values height = ??? image - SimpleImage.blank (width, height) for y in range(image. height): for x in range(image.width): pixel = image.get_pixel(x, y) # use pixel.red etc. in here # This displays image on screen image.show() Edit this code to set the pixel.red etc. of every pixel in the image using the parsed out values, using the provide range/y/x loops. This is a bit of a code puzzle. The range/y/x loops are going over the 2-d image. Each time through that loop, you want to grab the right parsed value. Think about which value you want the first time the loop runs, the second time, the third time, etc. to work out a pattern. The provided main() is set up to call your solve mystery() function when there is just 1 command line argument, like this: $ python3 parse-mystery.py 480k.txt Grayscale Pixels The following fact is needed for this puzzle: For each pixel in a grayscale image, the red, green, and blue values in each pixel must be equal. So for example a pixel might have red-50 green=50 blue=50 to be dark gray, or red=212 green=212 blue=212 to be light gray. Mystery Data The mystery campus object lives among the trees belbw lake Lagunita. It is somehow described in the file "480k.txt" which contains 480002 ints. The beginning of the list of ints looks like this (this is just the list your parse_file() returns): [800, 600, 64, 63, 61, 60, 74, 81, 55,... What could these 480002 numbers represent? It's a grayscale image! The first number is the width. The second number is the height. The remaining 480000 (800 * 600 - 480000) numbers are the grayscale values, one number per pixel. The pixel values are laid out in the 1-dimensional list. After the width and height are all the values of the top y 0 row, then all the values for y-1, then all the values for y 2 and so on in 1 big list: [width, height, y=0x=0, y=0x=1, y=0x-2, .... y=0x=799, y=1x=0, y=1x-2, y=1x=3 ... y=599x=799) This ordering of the pixels is the same, standard order that the range/y/x loops visit the pixels of an image. parse line(s): Given a string s, parse the ints out of it and retum them as a list of int values. >>> parse linel '12x76$'). (12, 67) >parse linel '800!)1764b006$ (46$*#632*16$+06$25') 1800, 600, 64, 63, 61, 60) Ist = search = while True: begin = search while begin len(s): break end - begin + 1 while end >> extract_nun( 'xx123$', 2, 5) 321 >>>> extract_nun( '176^', 2, 5) -1 if begin >= len(s): return -1 if end > len(s): return -1 s: if end