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