Python123基础测试题四道加大作业两题

1、判断奇偶数

2、百分制成绩转成五分制

3、各位数字和为5的数

4、输出三角形并计算面积

大作业:

1、哈姆雷特统计主要人物出现的次数

2、三国演义统计人物出现的次数

 

n = int(input())
if n % 2 == 0:
    print('even')
else:
    print('odd')

 

 

 

n = int(input())
if n >= 90:
    print('A')
elif n >= 80:
    print('B')
elif n >= 70:
    print('C')
elif n >= 60:
    print('D')
else:
    print('E')

 

n = eval(input())
for i in range(n+1):
    ge = i % 10
    shi = i // 10 % 10
    bai = i //100

    sum_ = ge + shi + bai
    if sum_ == 5:
        print(i,end='')

 

a = float(eval(input()))
b = float(eval(input()))
c = float(eval(input()))
s = (a+b+c)/2
if a+b>c and a+c>b and c+b>a:
    print("YES")
    print(f'{(s*(s-a)*(s-b)*(s-c))**0.5:.2f}')
else:
    print("NO")

 

 

 

 

name_dict = {
    'hamlet': 0,
    'claudius': 0,
    'gertrude': 0,
    'polonius': 0,
    'ophelia': 0,
    'laertes': 0,
    'horatio': 0,
    'rosencrantz': 0,
    'guildenstern': 0,
    'marcellus': 0
}
def getText():
    txt = open('hamlet.txt', 'r', encoding='utf-8').read()
    txt = txt.lower()
    for ch in '!"#$%&()*+,-./:;<=>?@[\n]^_`{|}~':
        txt = txt.replace(ch, ' ')
    return txt


words = getText().split(' ')
for word in words:
    if word in name_dict:
        name_dict[word] += 1

name_dict = sorted(list(name_dict.items()), key=lambda item: item[1], reverse=True)

for item in name_dict:
    print('{:<15}{:>2}'.format(item[0], item[1]))

import jieba
excludes={"将军","却说","二人","不可","荆州","不能","如此"}
txt=open("三国演义.txt","r",encoding='utf-8').read()
words=jieba.lcut(txt)
counts={}
for word in words:
    if len(word)==1: 
        continue
    elif word == '曹操':
        rword = '曹操'
    elif   word=="孔明":
        rword="孔明"
    elif word=="玄德":
        rword="玄德"
    elif word=="关公" :
        rword="关公"
    elif 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(5):
    word,count=items[i]
    print("{0:<10}{1:>5}".format(word,count))

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值