current position:Home>How to use stu method to input student names and grades in pyton and store them in the list

How to use stu method to input student names and grades in pyton and store them in the list

2022-02-02 23:02:03 CSDN Q & A

The dictionary structure for storing the scores of students Zhang San is as follows :
stu={"name":" Zhang San ","english":80,"python":90,"math":100}
1) Please use the above structure to enter 5 Of a student name And english、python and math The grades of the three courses are and stored in the list scores in ;
2) Calculate the average grade of each student , At the same time, add keywords to the dictionary "avg" Used to indicate average grade ;
3) The output is sorted from high to low according to the average score of each student 5 Information about students .




Refer to the answer 1:

The main answers are as follows

img

scores=[]for i in range(5):    stu={}    stu['name']=input(' Enter a name ')    stu['english']=int(input(' Enter English score '))    stu['python']=int(input(' Input python achievement '))    stu['math']=int(input(' Enter the math score '))    stu['avg']=(stu['english']+stu['python']+stu['math'])/3    scores.append(stu)scores.sort(key = lambda x:x["avg"],reverse =True)for stu in scores:    print(stu['name'],stu['english'],stu['python'],stu['math'],stu['avg'])

img

Helpful or enlightening. Please click here 【 Adopt the answer 】, thank you ~~ If you have other questions, you can continue to communicate ~




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022302017276.html

Random recommended