自己珍藏一些有趣的Python子程序
【摘要】
简 介: 这里收集了几个自己喜欢并且在之后有可能会被重复应用的Python小程序 关键词: Python
§01 汉字数字
一、从零到99
下面子程序...
§01 汉字数字
一、从零到99
下面子程序输出从0到99的数字的汉字数字字符串。
def chinesestr(num):
num1 = num // 10
num0 = num - num1*10
orderstr = '一二三四五六七八九十'
if num <= 0: return "零"
if num == 10: return "十"
if num < 10:
return orderstr[num-1]
if num < 20:
return "十"+orderstr[num0-1]
if num0 == 0:
return orderstr[num1-1] + '十'
return orderstr[num1-1] + '十' + orderstr[num0-1]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
二、从零到999
def chinesestr99(num):
num1 = num // 10
num0 = num - num1*10
orderstr = '一二三四五六七八九十'
if num <= 0: return "零"
if num == 10: return "十"
if num < 10:
return orderstr[num-1]
if num < 20:
return "十"+orderstr[num0-1]
if num0 == 0:
return orderstr[num1-1] + '十'
return orderstr[num1-1] + '十' + orderstr[num0-1]
def chinesestr999(num):
orderstr = '一二三四五六七八九十'
if num < 100: return chinesestr99(num)
if (num%100) == 0: return orderstr[num//100-1]+'百'
if (num%100) < 10: return orderstr[num//100-1] + "百零" + orderstr[(num%10)-1]
num3 = num//100
num2 = (num%100)//10
num1 = num%10
if num1 > 0: return '%s百%s十%s'%(orderstr[num3-1], orderstr[num2-1], orderstr[num1-1])
else: return '%s百%s十'%(orderstr[num3-1], orderstr[num2-1])
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
二、标题设置批处理
下面小程序对于CSDN编辑器中的标题进行批处理。
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST1.PY -- by Dr. ZhuoQing 2021-08-17
#
# Note:
#============================================================
from head import *
csdn_window = '写文章-CSDN博客'
tspsendwindowkey(csdn_window, "c", control=1)
strall = [s for s in clipboard.paste().split('\n') if len(s) > 0]
printf(strall)
#------------------------------------------------------------
def chinesestr99(num):
num1 = num // 10
num0 = num - num1*10
orderstr = '一二三四五六七八九十'
if num <= 0: return "零"
if num == 10: return "十"
if num < 10:
return orderstr[num-1]
if num < 20:
return "十"+orderstr[num0-1]
if num0 == 0:
return orderstr[num1-1] + '十'
return orderstr[num1-1] + '十' + orderstr[num0-1]
def chinesestr999(num):
orderstr = '一二三四五六七八九十'
if num < 100: return chinesestr99(num)
if (num%100) == 0: return orderstr[num//100-1]+'百'
if (num%100) < 10: return orderstr[num//100-1] + "百零" + orderstr[(num%10)-1]
num3 = num//100
num2 = (num%100)//10
num1 = num%10
if num1 > 0: return '%s百%s十%s'%(orderstr[num3-1], orderstr[num2-1], orderstr[num1-1])
else: return '%s百%s十'%(orderstr[num3-1], orderstr[num2-1])
#------------------------------------------------------------
insertall = ""
for id,t in enumerate(strall):
numstr = chinesestr99(id+1)
ts = "## <font face=黑体 color=purple>%s、%s</font>\n\n\n"%(numstr, t)
insertall = insertall + ts
printf(insertall)
clipboard.copy(insertall)
tspsendwindowkey(csdn_window, "v", control=1)
#------------------------------------------------------------
# END OF FILE : TEST1.PY
#============================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
文章来源: zhuoqing.blog.csdn.net,作者:卓晴,版权归原作者所有,如需转载,请联系作者。
原文链接:zhuoqing.blog.csdn.net/article/details/119759012
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)