RU beehive logo ITEC dept promo banner
ITEC 109
2014spring
ibarland

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs

lab39
nested ifs

Consider the following problem: At a bakery, you can order either donuts, or fritters:

def test():
    print( "0 donuts:" )
    print( "Actual:  " + str(orderPrice( "donuts", 0 )) )
    print( "Desired: " + str(...) )
    print( "1 donut:" )
    print( "Actual:  " + str(orderPrice( "donuts", 1 )) )
    print( "Desired: " + str(...) )
    print( "2 donuts:" )
    print( "Actual:  " + str(orderPrice( "donuts", 2 )) )
    print( "Desired: " + str(...) )
    print( "10 donuts:" )
    print( "Actual:  " + str(orderPrice( "donuts", 10 )) )
    print( "Desired: " + str(...) )
    print( "100 donuts:" )
    print( "Actual:  " + str(orderPrice( "donuts", 100 )) )
    print( "Desired: " + str(6175) )  # 6500¢ less 5% (325¢)

    print( "0 fritters:" )
    print( "Actual:  " + str(orderPrice( "fritter", 0 )) )
    print( "Desired: " + str(...) )
    print( "1 fritter:" )
    print( "Actual:  " + str(orderPrice( "fritter", 1 )) )
    print( "Desired: " + str(...) )
    print( "2 fritters:" )
    print( "Actual:  " + str(orderPrice( "fritter", 2 )) )
    print( "Desired: " + str(...) )
    print( "4 fritters:" )
    print( "Actual:  " + str(orderPrice( "fritter", 4 )) )
    print( "Desired: " + str(...) )
    print( "100 fritters:" )
    print( "Actual:  " + str(orderPrice( "fritter", 100 )) )
    print( "Desired: " + str(...) )
We'll go over the solution in class. You can see the solution here lab39-soln.html.


YOUR TASK:

  1. Write a function enhancePixelAt : Picture, int, int, → None, which takes in an image, an x-coordinate, and a y-coordinate, and changes the pixel according ot the following:
  2. Write enhance : Picture → None, which takes in a picture an enhances each pixel. (Of course, you'll want a helper-function enhanceOneRow : Picture, int → None
Use an if-else inside an if-else, to handle the three different cases. We'll spend tomorrow, finishing this up.

Note: You may adjust the exact conditions to your taste, if you think that would help the result look better. In particular, the first condition is perhaps a bit too lax, to just detect high-redness!
Note: The above description is intentionally a bit high-level — e.g. “set a pixel to black” might require three statements that we've used before.

1 A pixel's brightness is the sum of its red,green,blue channels divided by three (to bring it back into the range [0,256)).      

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs


©2014, Ian Barland, Radford University
Last modified 2014.Apr.18 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme