首页 / PYTHON / python之路002
python之路002
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python之路002,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1834字,纯文字阅读大概需要3分钟。
内容图文
![python之路002](/upload/InfoBanner/zyjiaocheng/850/96ece279e0c44e89b6a21401f09c3d10.jpg)
1.随机生成指定数量的手机号
''' @author:Mr_YJY @file:随机生成指定数量的手机号 @time:2018/10/21 ''' ''' 手机号是11位 电信:133 153 180。。。 联通:130 131 155。。。 移动:134 138 139。。。 第一位数:1 第二位数:3,4,5,7,8 第三位数:3:0-9 4:5,7,9 5:09,!=4 7:09,!=4,9 8:0-9 后8位:随机产生 ''' import random # 定义函数 def creat_phone(): # 第二位数 second=[3,4,5,7,8][random.randint(0,4)] # 根据第二数获取第三位数 third={ 3:random.randint(0,9), 4:[5,7,9][random.randint(0,2)], 5:[i for i in range(10)if i !=4][random.randint(0,8)], 7:[i for i in range(10) if i not in [4,9]][random.randint(0, 7)], 8:random.randint(0,9) }[second] # 获取后8位数 str_num = '' for i in range(8): index=random.randint(0,9) str_num=str_num+str(index) return '1{}{}{}'.format(second, third, str_num) # ba=random.randint(10000000,99999999)#简单 但缺少00000000-09999999 # return'1{}{}{}'.format(second,third,ba) # 调用 # num=creat_phone() # print(num) num=input("请输入生成的数量:") for index in range(0,int(num)): phone=creat_phone() print('第{}个电话号:{}'.format(index+1,phone))
2.整理桌面文件
''' @author:Mr_YJY @file:整理桌面文件 @time:2018/10/21 ''' import os import shutil # 桌面的路径 desktop=os.path.join(os.path.expanduser('~'),'Desktop') name = input('输入整理后的文件夹的名字:') clean = os.path.join(desktop,name) # 判断文件夹是否存在(true不创建;false创建) idExists=os.path.exists(clean) if idExists == False: os.mkdir(clean)# 创建文件夹 else: pass # 获取文件 name_list=os.listdir(desktop) # 分类 for file in name_list: filePath=os.path.join(desktop,file) if not os.path.isfile(filePath): continue elif os.path.isfile(filePath): # 分割文件名和拓展名 fileExpand=os.path.splitext(file)[1] fileExpand=fileExpand[1:] # print(fileExpand) # 创建文件夹 expand_file_name=os.path.join(clean,fileExpand) if not os.path.exists(expand_file_name): os.mkdir(expand_file_name) # 复制到指定路径下 shutil.move(filePath, expand_file_name)
内容总结
以上是互联网集市为您收集整理的python之路002全部内容,希望文章能够帮你解决python之路002所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】