Answer to Question #349925 in Python for Darkninja

Question #349925

# 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.


1
Expert's answer
2022-06-13T08:29:32-0400

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"]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS