python基础练习(四)_C

ntxt = input("请输入4个数字(空格分隔):")
nls=ntxt.split(" ")
x0 = eval(nls[0])
y0 = eval(nls[1])
x1 = eval(nls[2])
y1 = eval(nls[3])
r = pow(pow(x1-x0, 2) + pow(y1-y0, 2),0.5) 
print("{:.1f}".format(r))

python基础练习(四)_C_02
python基础练习(四)_C_03

import jieba
txt = input("请输入一段中文文本:")
ls=jieba.lcut(txt)
print("{:.1f}".format(len(txt)/len(ls)))

python基础练习(四)_C_04
python基础练习(四)_C_05
python基础练习(四)_C_06

n = eval(input("请输入一个数字:"))
print("{:+^11}".format(chr(n-1)+chr(n)+chr(n+1)))

python基础练习(四)_C_07
python基础练习(四)_C_08

import turtle
d = 0
for i in range(1,5):
    turtle.fd(200)
    d = i*90
    turtle.seth(d)

python基础练习(四)_C_09
python基础练习(四)_C_10

fo = open("PY202.txt","w")
data = input("请输入课程名及对应的成绩:")  # 课程名 考分
course_score_dict={}
while data:
    course,score=data.split(" ")
    course_score_dict[course]=eval(score)
    data = input("请输入课程名及对应的成绩:")
course_list=sorted(list(course_score_dict.values()))
max_score,min_score=course_list[-1],course_list[0]
average_age=sum(course_list)/len(course_list)
for item in course_score_dict.items():
    if item[1]==max_score:
        max_course=item[0]
    if item[1]==min_score:
        min_course=item[0]
fo.write("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(max_course,max_score,min_course,min_score,average_age))
fo.close()

python基础练习(四)_C_11

python基础练习(四)_C_12

python基础练习(四)_C_13
细致到空格!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

fi=open("sensor.txt","r")
fo=open("earpa001.txt","w")
txt=fi.readlines()
for line in txt:
    ls=line.strip("\n").split(",")
    if ' earpa001' in ls:
        fo.write('{},{},{},{}\n'.format(ls[0],ls[1],ls[2],ls[3]))
fi.close()
fo.close()

python基础练习(四)_C_14
python基础练习(四)_C_15
python基础练习(四)_C_16

fi=open("earpa001.txt","r")
fo=open("earpa001_count.txt","w")
d = {}
for line in fi:
    split_data=line.strip("\n").split(",")
    floor_and_area=split_data[-2]+"-"+split_data[-1]
    if floor_and_area in d:
        d[floor_and_area]+=1
    else:
        d[floor_and_area]=1
ls = list(d.items())
ls.sort(key=lambda x:x[1], reverse=True) # 该语句用于排序
for i in range(len(ls)):
  fo.write('{},{}\n'.format(ls[i][0],ls[i][1]))
fi.close()
fo.close()

python基础练习(四)_C_17