Calculate the average of Chinese scores in Student_grade.txt and find out who is the highest student in mathematics

Source: Internet
Author: User

Title: Calculate the average of Chinese scores in Student_grade.txt and find out who is the highest student in mathematics

Method One:

With open (' Student_grade.txt ', ' R ', encoding= ' utf-8 ') as f:    data = F.read ()                                         #读取student_grade. txt content to data (text) Data_lines=data.splitlines ()                                #把文本转换成列表 while removing the newline empty={}                                                    #定义一个空字典for i in Data_lines:                                            data_list=i.split ( ' \ t ')                                     empty[data_list[0]]=data_list[1:]                        #遍历列表data_lines中的每个元素, remove ' \ t ' after generating a dictionary of names and scores. Empty.pop (' name ')                                            #弹出标题行shuxue =0yuwen=0for k,v in Empty.items ():    yuwen=yuwen+int (v[0])                                   #遍历字典, the sum of the language results    if int (v[1]) > Shuxue:        shuxue=int (v[1])                                    #遍历字典empty, to find the highest mathematical results        name=kprint (name+ ' classmate of the highest mathematical performance, is%d. ') %shuxue, ' \ n ', ' The average language score is%d. '% ( Yuwen/len (empty)))   

  

Calculate the average of the language scores in Student_grade.txt, and find out who is the student with the highest math score

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.