´©Ô½Python Challenge
µÚ¾Å¹Ø Image
´ÓÒ³ÃæÉϵÄͼƬ¿ÉÒÔ¿´µ½ÓÐÒ»´®µã£¬ÄÇôÊDz»ÊÇ´ú±í¸Ã¹ØÓëͼÏñµãÓйأ¿ ÎÒÃÇ´ÓÒ³ÃæÔ´Âë¿ÉÒÔ¿´µ½£¬ÓÐÁ½¶ÎÊý×ÖÐòÁÐfirstºÍsecond£¬¶øÓÐÒ»¸öÌáʾfirst+second=? ʲôÒâ˼ÄØ£¿ÄѵÀÊÇ˵(first, second)´ú±íÁËͼÏñµãµÄ×ø±ê£¿²»Ïñ£¬Á½¶ÎÐòÁеij¤¶ÈÓкܴó²îÒì¡£ÄÇôËã·û+»¹ÓÐʲôº¬ÒåÄØ£¬ÓпÉÄÜÊǽ«Á½¶ÎÐòÁÐÆ´ÆðÀ´£¬È»ºóÿÁ½¸öÊý×Ö´ú±íÒ»¸öͼÏñµã¡£Í¨¹ý´¦Àí£¬ÎÒÃÇÔÚÔͼƬÉÏ°´ÕÕ¸ø¶¨µÄ×ø±êÍ¿ºÚµã£¬È´·¢ÏÖʲô¶¼¿´²»Ç壻Òò´ËÎÒÃÇ°´ÕÕͼƬµÄ¹æ¸ñн¨Ò»¸öͼƬ£¬ÔÚºÚµ×ÉÏÍ¿°×µã£¬´¦Àí³ÌÐòÈçÏ£º
#!/bin/python
# file: good.py
import re, Image
file = open('d:\Python\good.html')
message = re.findall('(<!--[^-]+-->)', file.read(), re.S)[1]
file.close()
first = re.findall('(\d+)',re.findall('first:(.+)second',message,re.S)[0],re.S)
second = re.findall('(\d+)',re.findall('second:(.+)>',message,re.S)[0],re.S)
all = first + second
im = Image.open('d:\Python\good.jpg')
im2 = Image.new(im.mode, im.size)
for x in range(0,len(all),2):
im2.putpixel((int(all[x]),int(all[x+1])),(255,255,255,255))
im2.show()
½á¹û³öÏÖһֻţµÄͼÑù£¬¸ù¾ÝÓ¢ÎÄƴд£¬ÎÒÃǵõ½cowµ¥´Ê£¬½øÈëÒ³Ãæ £¬µÃµ½Ìáʾ“hmm. it's a male. ” ÐÛÐÔµÄÅ££¿¹«Å£bull£¬½øÈëÒ³Ãæ £¬Í¨¹Ø£¡
µÚÊ®¹Ø ÐòÁÐÍÆÀí
ͼƬÏ·½ÓÐÒ»´®×Ö·û“len(a[30]) = ?”£¬Ñ§¹ý±à³ÌµÄ¶¼»áÒâʶµ½a¿ÉÄÜÊÇÒ»¸öÒÔ×Ö·û´®ÎªÔªËصÄÁÐ±í¡£ÄÇôa´ÓÄÄÀïÀ´ÄØ£¿ÎÒÃÇ¿´Ò³ÃæÔ´Â룬·¢ÏÖÓÐÒ»¸öhrefÁ´½Ó£¬´ò¿ªÍøÒ³ £¬ÎÒÃǵõ½Ìáʾ“a = [1, 11, 21, 1211, 111221, ”¡£ºÜÏÔÈ»£¬ÕâÐèÒªÎÒÃÇ´ÓÒÑÓеÄÊý×ÖÐòÁÐÖÐÕÒµ½¹æÂÉ£¬¼Ì¶ø¼ÆËã³öµÚ31¸öÔªËØ¡£Í¨¹ý˼¿¼£¬·¢ÏÖÿ¸öÔªËØÆäʵ¾ÍÊÇ°´Ë³Ðò¶ÔÇ°Ò»¸öÊý×ÖÐòÁеĽâÊÍ£¬±ÈÈç˵“21”°üº¬ÁË1¸ö2£¬1¸ö1£¬Òò´ËÏÂÒ»¸öÔªËØÊÇ‘2111’£¬°´ÕÕÕâÖÖ¹æÂÉ£¬‘111221’°üº¬ÁË3¸ö1£¬2¸ö2£¬1¸ö1£¬Òò´ËÏÂÒ»¸öÔªËØÓ¦¸ÃÊÇ‘312211’£¬ÎÒÃDZàд´úÂëÈçÏ£º
#!/bin/python
# file: getLength.py
strings = ['1','11']
for i in range(1,31):
j = 0
string = ''
while j < len(strings[i]):
count = 1
Ïà¹ØÎĵµ£º
# 005
# ÔÚPythonÖиø±äÁ¿¸³ÖµÊ±²»ÐèÒªÉùÃ÷Êý¾ÝÀàÐÍ
i = 33
print i
# ¿ÉÒÔÕâÑù×öµÄÔÒòÊÇPython°Ñ³ÌÐòÖÐÓöµ½µÄÈκζ«Î÷¶¼¿´³ÉÊǶÔÏó(Á¬intÒ²²»ÀýÍâ)
# ÕâÑù,ÔÚʹÓöÔÏóʱ,±àÒëÆ÷»á¸ù¾ÝÉÏÏÂÎĵĻ·¾³À´µ÷ÓöÔÏó×ÔÉíµÄ·½·¨Íê³ÉÒþʽµÄת»»
# ÄãÉõÖÁ¿ÉÒ԰ѳÌÐòд³ÉÕâÑù
print 3 * 'haha '
# µ«Èôд³ÉÕâÑù±àÒëÆ÷¾Í»á±¨´í ......
´úÂëºÜ¼òµ¥£¬²»µ½5kÐС£µ«ÊÇ˼·ͦºÃµÄ£¬¸Ä³Énon-blockingÁËÖ®ºóЧÂʾÍÊÇÄÜÌá¸ß²»ÉÙ£¬ÌرðÊÇ¿¼Âǵ½ÏÖ´úµÄweb app¶¼ÐèÒªºÍÆäËûµÄ
HTTP·þÎñÆ÷ͨÐÅ£¬blockingµÄ´ú¼ÛÌ«´óÁË¡£ Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application ......
¡¡¡¡ÓÐʱºò£¬Òª°ÑÄÚ´æÖеÄÒ»¸ö¶ÔÏó³Ö¾Ã»¯±£´æµ½´ÅÅÌÉÏ£¬»òÕßÐòÁл¯³É¶þ½øÖÆÁ÷ͨ¹ýÍøÂç·¢Ë͵½Ô¶³ÌÖ÷»úÉÏ¡£PythonÖÐÓкܶàÄ£¿éÌṩÁËÐòÁл¯Óë·´ÐòÁл¯µÄ¹¦ÄÜ£¬È磺marshal, pickle, cPickleµÈµÈ¡£½ñÌì¾Í½²½²marshalÄ£¿é¡£
¡¡¡¡×¢Ò⣺
marshal²¢²»ÊÇÒ»¸öͨÓõÄÄ£¿é£¬ÔÚijЩʱºòËüÊÇÒ»¸ö²»±»ÍƼöʹÓõÄÄ£¿é£¬ÒòΪʹÓÃmarshalÐ ......
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 033
class Person:
age = 22
def sayHello(self): # ·½·¨Ó뺯ÊýµÄÇø±ðÔÚÓÚÐèÒªÒ»¸öself²ÎÊý
print 'Hello!'
# end of def
# end of class # ÕâÊÇÎÒÁ¼ºÃµÄ±à³Ì·ç¸ñ
p = Person()
print p.age
p.sayHello()
output£º
22
Hello! ......
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
raiseÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸öÊÇÓÉÎÒÃÇ×Ô¼º¶¨ÒåµÄÒì³£ÀàÐÍ£¬µÚ¶þ¸öÊǹØÓÚ´ËÒì³£µÄÉÙÁ¿ËµÃ÷ÐÅÏ¢¡£
# 038
def getAge():
age = input('Input your age:')
if (age < 0 or age > 160):
raise 'BadAgeError', 'It is impossible!!!!!'
# end of if
return age
# ......