1. 血压统计

xy=[]
str1=input("")
while(str1!="end"):
    xyxm=str1.split(",")
    xy.append([xyxm[0],eval(xyxm[1]),eval(xyxm[2])])
    str1=input("")
#代码开始
bzc = []
for i in range(len(xy)):
    if xy[i][1]>=90 or xy[i][1]<=60 or xy[i][2]>=140 or xy[i][2]<=90:
        bzc.append(xy[i])
bfb = len(bzc)/len(xy)*100
#代码结束
print("不正常次数百分比{:.2f}".format(bfb))
for x in bzc:
    print("日期{}舒张压{}收缩压{}".format(x[0],x[1],x[2]))

2. 查找中心点

zb=[]
z=input()
while(z!="end"):
    x,y=z.split(',')
    zb.append([eval(x),eval(y)])
    z=input()
#代码开始
c = []
for a in range(len(zb)):
    s = 0
    for b in range(len(zb)):
        if a!=b:
            s += ((zb[a][0]-zb[b][0])**2+(zb[a][1]-zb[b][1])**2)**0.5
    c.append(s)
i = c.index(min(c))
mins = min(c)
#代码结束
print("最小值为第{}点坐标为({},{})距离之和为{:.2f}".format(i+1,zb[i][0],zb[i][1],mins))

3. 歌手评分计算

fs=[['zhang',9.5,9.8,9.7,9.6,9.5,9.9,9.6,9.2,9.3,9.7],
    ['huang',8.5,8.8,7.7,7.6,8.5,8.3,9.1,7.8,7.5,9.3],
    ['liu',9.5,8.8,7.2,9.6,8.5,6.5,6.3,7,6.9,9],
    ['chen',9.5,9.8,8.7,8.6,7.5,8.8,8.1,9.3,9.2,9.9],
    ['lin',9.9,7.8,7.5,7.2,6.5,9.1,9.2,9.3,8.5,8.2],
    ['ye',9.8,6.8,6.2,9.3,7.5,8.3,9.1,9.4,8.7,8.9]]
dict_p = {}
for i in range(len(fs)):
    b = sorted(fs[i][1:])
    del b[-1]
    del b[0]
    c = sum(b)/len(b)
    dict_p[fs[i][0]]=c
v = sorted(dict_p.values())
for key,value in dict_p.items():
    for i in range(1,4):
        if value == v[-i]:
            print("第{}名姓名{}分数{:.2f}".format(i,key,value))

4. 计算工资文件

from operator import itemgetter
f1=open("sy8//工资情况.csv","r",encoding="utf-8")
jg=[]
#代码开始
for line in f1:
    yh = line.strip("\n").split(",") 
    s = int(yh[1])+30*int(yh[2])+60*int(yh[3])
    jg.append([yh[0],s])
f1.close
jg.sort(key=itemgetter(1),reverse = True)
#代码结束
for y in jg:
    print("姓名{:8}\t工资{}".format(y[0],y[1]))

5. 列表处理

xlist=[]
for i in range(3):
    xlist.append([])
    for j in range(3):
        x=eval(input(""))
        xlist[i].append(x)
#代码开始
s = 0
for i in range(len(xlist)):
    for j in range(len(xlist[0])):
        s += xlist[i][j]
a = int(s/9)
ylist = []
for i in range(3):
    ylist.append([])
    for j in range(3):
        if xlist[i][j]>a:
            ylist[i].append(1)
        else:
            ylist[i].append(0)
#代码结束
for i in range(3):
    for j in range(3):
        print(ylist[i][j],end="")
    print('\n')

6. 用户文件增加

f1=open("sy8\\pd.csv","r+")
yhm=input("用户名")
mm=input("密码")
#代码开始
r = f1.read()
k=r.split("\n")
del k[-1]
yh = []
for i in range(len(k)):
    y = k[i].split(',')
    yh.append(y)
for i in range(len(yh)):
    if yh[i][0]==yhm and yh[i][1] == mm:
        print("用户已存在")
        c = True
        break
    elif yh[i][0]!=yhm and yh[i][1] != mm:
        c = False
if c == False:
    ls = yhm+','+mm+'\n'
    f1.write(ls)
f1.close()
#代码结束
f2=open("sy8\\pd.csv","r")
for line in f2:
    yh=line.strip("\n").split(",")
    print("用户名{}密码{}".format(yh[0],yh[1]))
f2.close()

7. 用户文件删除

f1=open("sy8\\pd.csv","r")
yhm=input("用户名")
#代码开始
lines = f1.readlines()
f1.close()

with open("sy8\\pd.csv","w") as w:
    count = 0
    for l in lines:
        if yhm not in l:
            w.write(l)
            count += 1
    if count == 5:
        print("该用户不存在")
        
#代码结束
f2=open("sy8\\pd.csv","r")
for line in f2:
    yh=line.strip("\n").split(",")
    print("用户名{}密码{}".format(yh[0],yh[1]))
f2.close()

8. 用户文件修改密码

f1=open("sy8\\pd.csv","r")
yhm=input("用户名")
mm=input("密码")
#代码开始
lines = f1.readlines()
count = 0
for line in lines:
    yh=line.strip("\n").split(",")
    if (yh[0]==yhm and yh[1]!=mm) or (yh[0]!=yhm and yh[1]==mm):
        print("用户名或密码错误")
        break
    elif yh[0]==yhm and yh[1]==mm:
        k1 = input('新密码')
        k2 = input('新密码')
        if k1 != k2:
            print("两次密码不一致")
        else:
            count = 1
f1.close()
if count == 1:
    with open("sy8\\pd.csv","w") as w:
        for l in lines:
            if mm in l:
                l = l.replace(mm,k1)
            w.write(l)

#代码结束
f2=open("sy8\\pd.csv","r")
for line in f2:
    yh=line.strip("\n").split(",")
    print("用户名{}密码{}".format(yh[0],yh[1]))
f2.close()
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐