关于python的学习

1.统计 this.txt 文件中字母(‘a’-‘z’)、大写字母( ‘A’-‘Z’)、数字(0-9)、其他字符的个数。

import os
with open(r"C:/Users/songcx/Downloads/this.txt") as f:
    small_letter=0
    big_letter=0
    number=0
    others=0
    while True:
        s=f.readline()
        if not s:
            break;
        else:
            s=s.strip('\n')
            i=0
            for i in s:
                if(i>='a' and i<='z'):
                    small_letter+=1
                elif i>='A' and i<='Z':
                    big_letter+=1
                elif i>='0' and i<='9':
                    number+=1
                else:
                    others+=1
    print('小写字母:%d'%small_letter)
    print('大写字母:%d'%big_letter)
    print('数字:%d'%number)
    print('其他符号:%d'%others)

2.实现类似DOS命令中的tree命令功能。

import os
path="D:/SCX"
def print_tree(path,depth):
    pathlist=os.listdir(path)
    for i in pathlist:
        print("|  " * depth +"|___"+i)
        f=open("C:/Users/songcx/Desktop/tree.txt","a")
        f.write("|  " * depth +"|___"+i+"\n")
        f.close()
        path_name=os.path.join(path,i)
        if  os.path.isdir(path_name):
          print_tree(path_name,depth+1)
print_tree(path,0)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值