Generate 200 10-bit random numbers (Generate coupons): __author__ = ' Friday ' import random
def creat_num (num,long): str = ' [email protected]#$%^&*_+ ' B = [] for i in range (num): a = ' F or j in range (long): A + = Random.choice (str) b.append (a) for I in range (len (b)): Print (B[i])
if __name__ = = ' __main__ ': Creat_num (200,10)
Determine how many English words you have: Import refrom collections Import Counter
def word_count (txt): Word_pattern = R ' [a-za-z-]+ ' words = Re.findall (word_pattern, TXT) return Counter (words). ite MS ()
if __name__ = = ' __main__ ': txt = open (' D:\\f.txt ', ' R '). Read (). lower () print word_count (TXT)
Add a number to the Avatar: __author__ = ' KXRR '
From PIL import Image,imagedraw,imagefontimport random
Msgnum = str (random.randint (1,99))
# Read Imageim = Image.open (' d:\\1.jpg ') w,h = Im.sizewdraw = 0.8 * Whdraw = 0.08 * W
# Draw Imagefont = Imagefont.truetype (' D:\\1.TTC ', #) # Use absolute font path to fix ' ioerror:cannot open resource ' Draw = Imagedraw.draw (IM) Draw.text ((Wdraw,hdraw), Msgnum, Font=font, fill= (255,33,33))
# Save Imageim.save (' d:\\kxrr_msg.png ', ' png ')
there is a directory in which you have written your own program, counting how many lines of code you have written. Include blank lines and comments, but are listed separately.
Import Osimport RE
def find_path (path): c = 0 for I in Os.listdir (path): Py=os.path.join (path,i) a=open (py) commen Tline = 0 Blankline = 0 lines = Len (A.readlines ()) print "There is%d lines in%s"% (lines, py) For II in A.readlines (): pattern = Re.compile (R ' (\s*) # ') Pattern1 = Re.compile (R ' (\s*) $ ') If Pattern.match (ii): Commentline + = 1 if Pattern1.match (ii): BLA Nkline + = 1 print "Blankline is:", Blankline, "Commentline is:", commentline
Find_path (' D://1 ')
From for notes (Wiz)
Small programs that have been written