博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第四次作业
阅读量:5020 次
发布时间:2019-06-12

本文共 1875 字,大约阅读时间需要 6 分钟。

要求:

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))

 

转载于:https://www.cnblogs.com/goddessing/p/10841510.html

你可能感兴趣的文章
hdu 2795 Billboard(线段树+单点更新)
查看>>
本博客所有技术文章皆转自网络
查看>>
sass最佳实践
查看>>
移动端笔记
查看>>
Behaviac 腾讯开源行为树 简介(给策划)
查看>>
js:鼠标事件
查看>>
bzoj 2005: [Noi2010]能量采集
查看>>
2016级算法第一次练习赛-E.AlvinZH的儿时回忆——蛙声一片
查看>>
2016级算法第三次上机-G.Winter is coming
查看>>
SSAS使用MDX生成脱机的多维数据集CUB文件
查看>>
ACM_hdu1102最小生成树练习
查看>>
MyBatis源码分析(一)--SqlSessionFactory的生成
查看>>
android中ListView点击和里边按钮或ImageView点击不能同时生效问题解决
查看>>
CTF常用工具之汇总
查看>>
java的面向对象 (2013-09-30-163写的日志迁移
查看>>
HDU 2191 【多重背包】
查看>>
51nod 1433 0和5【数论/九余定理】
查看>>
【AHOI2013复仇】从一道题来看DFS及其优化的一般步骤和数组分层问题【转】
查看>>
less 分页显示文件内容
查看>>
如何对数据按某列进行分层处理
查看>>