- 博客(2)
- 收藏
- 关注
原创 Python——实现英文词频统计:以hamlet为例
中国大学MOOC 嵩天老师在课堂上讲解的,附上代码和详细注释。 代码和文本文件需要放到同一目录下。 def getText(): txt = open("hamlet.txt","r").read() txt = txt.lower() # 将所有字符转换为小写 for ch in '!@#$%^&*()":;?,.><+=-_{}[\\]\/|`~': #将所有特殊符号用空格替代 txt = txt.replace(ch," ") .
2021-06-23 16:32:59 3144
原创 python——打印显示任务的进度条
import time scale = 10 #打印的字符宽度 print("------执行开始------") for i in range(scale + 1): a = '*' * i b = '.' * (scale - i) c = (i/scale) * 100 print("{:^3.0f}%[{}->{}]".format(c,a,b)) #居中对齐,宽度为3,精度为.0 ,类型为浮点型。 time.sleep(0.2) #执行完一次打.
2021-06-17 22:12:09 1034 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人