Skip to content

Commit a941958

Browse files
committed
进行文本整理
1 parent 8d10a89 commit a941958

File tree

7 files changed

+80
-68
lines changed

7 files changed

+80
-68
lines changed

源代码/AutoTraceDraw.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import turtle
22
turtle.title("自动轨迹绘制")
3-
turtle.setup(800,600,0,0)
3+
turtle.setup(800, 600, 0, 0)
44
turtle.pencolor("red")
55
turtle.pensize(5)
6-
datals=[]
7-
f=open("date.txt","r",encoding="utf-8")
6+
datals = []
7+
f = open("date.txt", "r", encoding="utf-8")
88
for line in f:
9-
line=line.replace("\n","")
10-
datals.append(list(map(eval,line.split(","))))
9+
line = line.replace("\n", "")
10+
datals.append(list(map(eval, line.split(","))))
1111
f.close()
1212
for i in range(len(datals)):
13-
turtle.pencolor(datals[i][3],datals[i][4],datals[i][5])
13+
turtle.pencolor(datals[i][3], datals[i][4], datals[i][5])
1414
turtle.fd(datals[i][0])
1515
if datals[i][1]:
1616
turtle.right(datals[i][2])

源代码/CalHamlet1.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
def getTxt():
2-
txt=open("hamlet.txt","r",encoding="utf-8").read()
3-
txt=txt.lower()
2+
txt = open("hamlet.txt", "r", encoding="utf-8").read()
3+
txt = txt.lower()
44
for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~':
5-
txt=txt.replace(ch," ")
5+
txt = txt.replace(ch, " ")
66
return txt
7-
hamletTxt=getTxt()
8-
words=hamletTxt.split()
9-
counts={}
10-
for word in words:
11-
counts[word]=counts.get(word,0)+1 #get方法对字典的word判断是否存在不存在赋值为0,存在则索引word+1
12-
items=list(counts.items())
13-
items.sort(key=lambda x:x[1],reverse=True)
7+
8+
9+
hamletTxt = getTxt()
10+
words = hamletTxt.split()
11+
counts = {}
12+
for word in words: # get方法对字典的word判断是否存在不存在赋值为0,存在则索引word+1
13+
counts[word] = counts.get(word, 0)+1
14+
items = list(counts.items())
15+
items.sort(key=lambda x: x[1], reverse=True)
1416
for i in range(10):
15-
word,count=items[i]
16-
print("{0:<10}{1:>5}".format(word,count))
17+
word, count = items[i]
18+
print("{0:<10}{1:>5}".format(word, count))

源代码/CalThreeKingdoms.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import jieba
2-
f=open("三国演义上.txt","r",encoding="utf-8")
3-
txt1=f.read()
2+
f = open("三国演义上.txt", "r", encoding="utf-8")
3+
txt1 = f.read()
44
f.close()
5-
f=open("三国演义下.txt","r",encoding="utf-8")
6-
txt2=f.read()
5+
f = open("三国演义下.txt", "r", encoding="utf-8")
6+
txt2 = f.read()
77
f.close()
8-
txt=txt1+txt2
9-
excludes={"将军","却说","荆州","二人","不可","不能","如此","军士","天下","主公","商议","如何","徐州","左右","先生","次日",\
10-
"江东","百姓","军马","引兵","大喜","东吴","于是","今日","不敢","魏兵","陛下","一人","都督","人马","不知"}
11-
words=jieba.lcut(txt)
12-
counts={}
8+
txt = txt1+txt2
9+
excludes = {"将军", "却说", "荆州", "二人", "不可", "不能", "如此", "军士", "天下", "主公", "商议", "如何", "徐州", "左右", "先生", "次日",
10+
"江东", "百姓", "军马", "引兵", "大喜", "东吴", "于是", "今日", "不敢", "魏兵", "陛下", "一人", "都督", "人马", "不知"}
11+
words = jieba.lcut(txt)
12+
counts = {}
1313
for word in words:
14-
if len(word)==1:
14+
if len(word) == 1:
1515
continue
16-
elif word=="诸葛亮"or word=="孔明曰":
17-
rword="孔明"
18-
elif word=="关公"or word=="云长":
19-
rword="关羽"
20-
elif word=="玄德"or word=="玄德曰":
21-
rword="刘备"
22-
elif word=="孟德"or word=="丞相":
23-
rword="曹操"
16+
elif word == "诸葛亮"or word == "孔明曰":
17+
rword = "孔明"
18+
elif word == "关公"or word == "云长":
19+
rword = "关羽"
20+
elif word == "玄德"or word == "玄德曰":
21+
rword = "刘备"
22+
elif word == "孟德"or word == "丞相":
23+
rword = "曹操"
2424
else:
25-
rword=word
26-
counts[rword]=counts.get(rword,0)+1
25+
rword = word
26+
counts[rword] = counts.get(rword, 0)+1
2727
for word in excludes:
2828
del counts[word]
29-
items=list(counts.items())
30-
items.sort(key=lambda x:x[1],reverse=True)
29+
items = list(counts.items())
30+
items.sort(key=lambda x: x[1], reverse=True)
3131
for i in range(10):
32-
word,count=items[i]
33-
print("{0:<10}{1:>5}".format(word,count))
32+
word, count = items[i]
33+
print("{0:<10}{1:>5}".format(word, count))

源代码/DrawPython.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import turtle
2-
turtle.setup(650,350,200,200)
2+
turtle.setup(650, 350, 200, 200)
33
turtle.penup()
44
turtle.fd(-250)
55
turtle.pendown()
66
turtle.pensize(25)
77
turtle.pencolor("purple")
88
turtle.seth(-40)
99
for i in range(4):
10-
turtle.circle(40,80)
11-
turtle.circle(-40,80)
12-
turtle.circle(40,80/2)
10+
turtle.circle(40, 80)
11+
turtle.circle(-40, 80)
12+
turtle.circle(40, 80/2)
1313
turtle.fd(40)
14-
turtle.circle(16,180)
14+
turtle.circle(16, 180)
1515
turtle.fd(40*2/3)
16-
turtle.done()
16+
turtle.done()

源代码/GovRptWordCloud.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import jieba
22
import wordcloud
3-
f=open("新时代中国特色社会主义.txt","r",encoding="utf-8")
4-
t=f.read()
3+
f = open("新时代中国特色社会主义.txt", "r", encoding="utf-8")
4+
t = f.read()
55
f.close()
6-
ls=jieba.lcut(t)
7-
txt=" ".join(ls)
8-
w=wordcloud.WordCloud(font_path="msyh.ttc",width=1000,height=700,background_color="white")
6+
ls = jieba.lcut(t)
7+
txt = " ".join(ls)
8+
w = wordcloud.WordCloud(font_path="msyh.ttc", width=1000,
9+
height=700, background_color="white")
910
w.generate(txt)
1011
w.to_file("ntwordcloud.png")
11-
12-
13-

源代码/SevenDIgitDraw.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import turtle
22
import time
3-
def drawGap ():
3+
4+
5+
def drawGap():
46
turtle.penup()
57
turtle.fd(5)
8+
9+
610
def drawLine(draw):
711
drawGap()
812
turtle.pendown() if draw else turtle.penup()
913
turtle.fd(40)
1014
drawGap()
1115
turtle.right(90)
16+
17+
1218
def drawDigit(digit):
1319
drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
1420
drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
@@ -21,28 +27,34 @@ def drawDigit(digit):
2127
turtle.left(180)
2228
turtle.penup()
2329
turtle.fd(20)
30+
31+
2432
def drawDate(date):
2533
for i in date:
2634
turtle.color('purple')
27-
if i=='-':
35+
if i == '-':
2836
turtle.color('red')
2937
turtle.write("年", font=("Arial", 18, "normal"))
3038
turtle.fd(40)
31-
elif i=='=':
39+
elif i == '=':
3240
turtle.color('yellow')
3341
turtle.write('月', font=("Arial", 18, "normal"))
3442
turtle.fd(40)
35-
elif i=='+':
43+
elif i == '+':
3644
turtle.color('green')
3745
turtle.write('日', font=("Arial", 18, "normal"))
3846
else:
39-
drawDigit(eval(i))
47+
drawDigit(eval(i))
48+
49+
4050
def main():
41-
turtle.setup(800,350,200,200)
51+
turtle.setup(800, 350, 200, 200)
4252
turtle.penup()
4353
turtle.fd(-300)
4454
turtle.pensize(5)
45-
drawDate(time.strftime("%Y-%m=%d+",time.gmtime()))
55+
drawDate(time.strftime("%Y-%m=%d+", time.gmtime()))
4656
turtle.hideturtle()
4757
turtle.done()
48-
main()
58+
59+
60+
main()

源代码/rainbow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import turtle
2-
size=15
2+
size = 15
33
turtle.pensize(15)
44
for i in range(7):
55
if i == 0:
@@ -17,8 +17,8 @@
1717
if i == 6:
1818
turtle.color('red')
1919
turtle.circle(size)
20-
size+=15
21-
if i==6:
20+
size += 15
21+
if i == 6:
2222
break
2323
turtle.seth(-90)
2424
turtle.penup()
@@ -30,4 +30,4 @@
3030
turtle.color('purple')
3131
turtle.pensize(17)
3232
turtle.fd(200)
33-
turtle.done()
33+
turtle.done()

0 commit comments

Comments
 (0)