第1关:统计文档中作者作品数量
f1=open("sy9//中学诗词.txt","r",encoding='utf-8')
#代码开始
#代码结束
for i in lt:
print(i[0],i[1])
f1.close()
第2关:候选人票数统计
tp=[]
x=input("")
while(x!="end"):
tp.append(x)
x=input("")
#代码开始
#代码结束
for i in range(len(items)):
print("第{}名姓名{}票数{}".format(i+1,items[i][0],items[i][1]))
第3关:会员会费计算
f1=open("sy9//会员名单.txt","r",encoding="utf8")
#代码开始
#代码结束
f1.close()
第4关:职工工资计算
zg=[]
xx=input("")
while(xx!="end"):
sj=xx.split(',')
zg.append([sj[0],eval(sj[1]),sj[2],sj[3]])
xx=input("")
#代码开始
#代码结束
for x in yfgz:
print("姓名"+x[0]+"工资"+str(x[1]))
第5关:文件币种兑换计算
f1 = open("sy9//汇率兑换.txt", "r", encoding="utf-8")
d, t = {}, 0
#代码开始
for i in f1:
i = i.strip()
a = i.find('(')
b = i.find('=')
d[i[a+1:a+4]] = float(i[b+2:b+8])
while True:
x = input()
if x == '0':
break
for i in x[3:]:
if i.isnumeric() == False:
print('数字错误')
t = 1
break
if x[0:3].upper() in d.keys() and t == 0:
sums = float(x[3:]) * d[x[0:3].upper()]
print('人民币{:.2f}'.format(sums))
if x[0:3].upper() not in d.keys() and t == 0:
print('币种错误')
#代码结束
f1.close()
第6关:饮品销售计算
f1=open("sy9//nc.csv","r",encoding="utf8")
#代码开始
#代码结束
print("应付{}元".format(je))
第7关:统计文件词语的词频
import jieba
f1 = open("sy9//宋词.txt", "r")
#代码开始
d, s = {}, ''
for i in f1:
if i.find(" ") == -1:
s += i
l = jieba.lcut(s)
for i in l:
if len(i) == 2:
d[i] = d.get(i, 0) + 1
lb = list(d.items())
lb.sort(key=lambda x:x[1], reverse=True)
#代码结束
for i in range(15):
print("{}{}".format(lb[i][0], lb[i][1]))
第8关:宋词文件词云图片
import jieba
import wordcloud as wc
f1 = open("sy9//宋词.txt", "r")
#代码开始
s1, s2 = '', ''
for i in f1:
if i.find(" ") == -1:
s1 += i
l = jieba.lcut(s1)
for i in l:
if len(i) == 2:
s2 += i + ' '
w = wc.WordCloud(height=700, width=1000, max_words=300, font_path='sy9//simhei.ttf', background_color='white').generate(s2)
#代码结束
w.to_file("sy9//pict//sc1.png")