写过的小程序

生成200个10位的随机数(生成优惠券):
__author__ = 'friday'
import random

def creat_num(num,long):
    str = 'qwertyuiopasdfghjklzxcvbnm1234567890!@#$%^&*_+'
    b = []
    for i in range(num):
        a = ''
        for 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) 

判断有多少个英文单词:
import re
from collections import Counter


def word_count(txt):
    word_pattern = r'[a-zA-Z-]+'
    words = re.findall(word_pattern, txt)
    return Counter(words).items()

if __name__ == '__main__':
    txt = open('D:\\f.txt', 'r').read().lower()
    print word_count(txt)


为头像加数字:
__author__ = 'Kxrr'

from PIL import Image,ImageDraw,ImageFont
import random

msgNum = str(random.randint(1,99))

# Read image
im = Image.open('D:\\1.jpg')
w,h = im.size
wDraw = 0.8 * w
hDraw = 0.08 * w

# Draw image
font = ImageFont.truetype('D:\\1.ttc', 30) # 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 image
im.save('D:\\kxrr_msg.png', 'png') 

有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
import os
import re

def find_path(path):
    c = 0
    for i in os.listdir(path):
        py=os.path.join(path,i)
        a=open(py)
        commentline = 0
        blankline = 0
        lines = len(a.readlines())
        print "There are %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):
                    blankline += 1
        print "blankline is:",blankline,"commentline is:",commentline

find_path('d://1')









转载于:https://www.cnblogs.com/tangbinghaochi/p/6292990.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值