zoukankan      html  css  js  c++  java
  • 文件简单操作

    score.txt 文件内容
    
    李彦宏 男 英语 80
    
    李彦宏 男 电子技术基础 75
    
    李彦宏 男 Python程序设计 88
    
    马云 男 英语 62
    
    马云 男 电子技术基础 63
    
    马云 男 Python程序设计 68
    
    黄蓉 女 英语 90
    
    黄蓉 女 电子技术基础 80
    
    黄蓉 女 Python程序设计 65

    lis1 = list()
    lis2 = list()
    dic = dict()
    
    with open('score.txt', 'r',encoding='utf-8') as f:
     for line in f:
      line = line.replace("
    ", "")
      if (line != ""):
       lis = line.split(" ")
       tuple1 = tuple(lis)
    
       if (tuple1[2] == 'Python程序设计'):
        dic[tuple1[3]] = tuple1[2]
       if (tuple1[1] == ''):
        lis1.append(int(tuple1[3]))
       else:
        lis2.append(int(tuple1[3]))
    
    sum_male = 0
    sum_female = 0
    sum_python = 0
    
    for i in lis1:
     sum_male += i
    for i in lis2:
     sum_female += i
    for i in dic.keys():
     sum_python += int(i)
    
    print("该班的男生平均成绩为:{0}  
    女生平均成绩为:{1}".format(sum_male / len(lis1), sum_female / len(lis2)))
    print("该班Python程序设计的平均成绩为:", sum_python / len(dic))
    f.close()


    2020-05-28 

  • 相关阅读:
    OCP-1Z0-053-V12.02-285题
    OCP-1Z0-053-V12.02-281题
    今天博客抽风了,我也抽风了
    OCP-1Z0-053-V12.02-278题
    OCP-1Z0-053-V12.02-271题
    OCP-1Z0-053-V12.02-269题
    OCP-1Z0-053-V12.02-256题
    OCP-1Z0-053-V12.02-249题
    OCP-1Z0-053-V12.02-248题
    OCP-1Z0-053-V12.02-244题
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12978701.html
Copyright © 2011-2022 走看看