1.22.2013 #Practical Programming #3

# 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 - 
# ------------------------------------------------------------------------------


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值