要求:
1.初始化start_day,end_day两个日期
from datetime import datetime
start_day=datetime(2019,4,1)
end_day=datetime(2019,4,30)
其它时间数据生成要用datetime或date模块的方法编程实现
2.不能使用calendar模块生成
from datetime import datetime
start_day = datetime(2019, 4, 1)
end_day = datetime(2019, 4, 30)
print("\t\t2019年4月")
print("星期一 星期二 星期三 星期四 星期五 星期六 星期天")
day = end_day - start_day
month = start_day.month
first = start_day.weekday()
day = day.days + 1
count = 0
k = 1
while k <= first:
k += 1
print("\t", end="")
count += 1
if (count % 7 == 0):
print("\n")
f = 1
while f <= day:
print(f, end="\t")
f += 1
count += 1
if (count % 7 == 0):
print("\n")
设计题2:
1.参考“三国演义”词频统计程序,实现对红楼梦出场人物的频次统计。
2.(可选)
将红楼梦出场人物的频次统计结果用词云显示。
import jieba excludes = {"什么","一个","我们","那里","你们","如今","说道","知道","起来","姑娘","这里","出来","他们","众人","自己", "一面","只见","太太","奶奶","两个","没有","不是","不知","这个","听见","这样","进来","咱们","告诉","怎么", "就是","东西","回来","只是","老爷","大家","只得","丫头","这些","不敢","出去","所以","的话","不好","姐姐", "鸳鸯"} txt = open(r"D:\work\红楼梦.txt", "r", encoding='utf-8').read() words = jieba.lcut(txt)
counts = {}
for word in words: if len(word) == 1: continue
elif word == "宝玉" or word == "宝二爷"or word=="怡红公子"or word=="绛洞花主"or word=="槛内人"or word=="浊玉": rword = "贾宝玉"
elif word == "颦颦" or word == "颦儿" or word=="潇湘妃子" or word=="林姑娘" or word=="林妹妹"or word=="黛玉": rword = "林黛玉"
elif word == "凤姐" or word == "琏二奶奶" or word=="凤辣子"or word=="凤哥儿"or word=="凤丫头" or word=="凤姐儿": rword = "王熙凤"
elif word == "贾母" or word == "老太太": rword = "贾母"
elif word == "宝钗" or word == "蘅芜君"or word == "宝姐姐" or word == "宝丫头" or word == "宝姑娘": rword = "薛宝钗"
else: rword = word counts[rword] = counts.get(rword,0) + 1
for word in excludes: del(counts[word])
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True) for i in range(10):
word, count = items[i]
print ("{0:<10}{1:>5}".format(word, count))