def get_score(who, students, scores):
'''
Purpose: Print a student's and their scores.
Pre: who is a string. students is a list of names (strings).
scores is a list of scores (ints or floats). students
and scores are parallel lists.
Post: returns the score corresponding to the named student.
If that student was not found, returns 0.
'''
result = 0
if who in students:
# Find the student
pos = students.index(who)
result = scores[pos]
# Otherwise, result is still zero.
return result
def get_a_students(students, scores):
'''
Purpose: Find students with scores >= 90.
Pre: students is a list of names (strings). scores is a list
of scores (ints or floats). students and scores are
parallel lists.
Post: returns a new list of the names of those students whose
scores are greater than or equal to 90.
'''
result = []
for i in range(len(students)):
if scores[i] >= 90:
result.append(students[i])
return result
def main():
'''Driver program for gradequiz.'''
students = [ "Doe", "Roe", "Smith", "Jones", "Wang", "Diaz" ]
scores = [ 75, 88, 93, 83, 78, 94 ]
print("All students:")
# Print the scores of all students (in order)
for st in students:
sc = get_score(st, students, scores)
print(st, ":", sc)
print()
a_students = get_a_students(students, scores)
print("Students with 'A's only:")
for st in a_students:
sc = get_score(st, students, scores)
print(st, ":", sc)
main()