# Practical Programming
# Exercise - 4.8
# 1 - math
# ------------------------------------------------------------------------------
#import math
#print abs(round(-4.3))
#print math.ceil(math.sin(34.5))
# 2 - calendar
# ------------------------------------------------------------------------------
#import calendar
#i = 2013
#while not calendar.isleap(i):
#i += 1
#print 'The following leap year is:', i
#print 'There are %d leap years between year 2000 and year 2050' % calendar.leapdays(2000, 2050)
#days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
#print '2016.7.29 is %s' % days[calendar.weekday(2016, 7, 29)]
# 3 - string functions
# ------------------------------------------------------------------------------
#print 'boolean'.capitalize()
#print 'C02 H20'.find('2')
#print 'C02 H20'.find('2',3)
#print 'Boolean'.startswith('b')
#print 'MoNDaY'.lower().capitalize()
#print ' Monday'.strip(' ')
# 6 - choose a picture and show it twice.
# ------------------------------------------------------------------------------
#import media
#path = media.choose_file()
#pic = media.load_picture(path)
#pic2 = media.load_picture(path)
#media.show(pic)
#media.show(pic2)
# 7 - set red to 0.
# ------------------------------------------------------------------------------
#import media
#path = media.choose_file()
#pic = media.load_picture(path)
#pic2 = media.load_picture(path)
#media.show(pic)
#for p in media.get_pixels(pic2):
#new_red = 0;
#media.set_red(p, new_red)
#media.show(pic2)
# 8 - half green
# ------------------------------------------------------------------------------
#import media
#path = media.choose_file()
#pic = media.load_picture(path)
#pic2 = media.load_picture(path)
#media.show(pic)
#for p in media.get_pixels(pic2):
#new_green = int(0.5 * media.get_green(p))
#media.set_green = (p, new_green)
#media.show(pic2)
# 9 - greyscale
# ------------------------------------------------------------------------------
#import media
#path = media.choose_file()
#pic = media.load_picture(path)
#pic2 = media.load_picture(path)
#media.show(pic)
#for p in media.get_pixels(pic2):
#average = int((media.get_red(p) + media.get_green(p) + media.get_blue(p)) / 3.0)
#'''greyscale = calculate the average of red, green, and blue values of each pixel.'''
#media.set_red(p, average)
#media.set_green(p, average)
#media.set_blue(p, average)
#media.show(pic2)
# 10 - double the red
# ------------------------------------------------------------------------------
#import media
#path = media.choose_file()
#pic = media.load_picture(path)
#pic2 = media.load_picture(path)
#media.show(pic)
#for p in media.get_pixels(pic2):
#'''double the red value of each pixel. if the doubled value lager than 255, then set it to 255.'''
#doubled_red = 2 * media.get_red(p)
#if doubled_red <= 255:
#media.set_red(p, doubled_red)
#media.set_red(p, 255)
#media.show(pic2)
# 11 -
# ------------------------------------------------------------------------------
09-14
09-14
09-14
09-14