# Accept student name and grade and save it to a dictionary.
# Display the content of the dictionary.
# Display the name and grade of student with the highest and lowest grade.
Clarifications for your question.
print("Enter the student's name and grade separated by a space. Leave an empty line to end input.")
i=1
d={}
sting_in = input('Student #'+str(i)+':')
while sting_in!="":
d['st'+str(i)]={'number':i, 'name': sting_in.split()[0], 'grade': int(sting_in.split()[1])}
i=i+1
sting_in = input('Student #'+str(i)+':')
print("Dictionary content")
print(d)
st_max_key=[]
st_min_key=[]
st_max_grade=d["st1"]["grade"]
st_min_grade=d["st1"]["grade"]
for key in d.keys():
if st_max_grade<d[key]["grade"]:
st_max_grade=d[key]["grade"]
if st_min_grade>d[key]["grade"]:
st_min_grade=d[key]["grade"]
for key in d.keys():
if st_max_grade==d[key]["grade"]:
st_max_key.append(key)
if st_min_grade==d[key]["grade"]:
st_min_key.append(key)
print('Students list')
for key in d.keys():
print('Student #'+str(d[key]["number"])+" Name: "+d[key]["name"]+' Grade: '+str(d[key]["grade"]))
print('The name of the student with the highest score:')
for key in st_max_key:
print('Student #'+str(d[key]["number"])+" Name: "+d[key]["name"]+' Grade: '+str(d[key]["grade"]))
print('The name of the student with the lowest grade:')
for key in st_min_key:
print('Student #'+str(d[key]["number"])+" Name: "+d[key]["name"]+' Grade: '+str(d[key]["grade"]))
Comments
Leave a comment