Small programs that have been written

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.