Nov-14-2018, 02:41 AM
You could use a dictionary to pair up the student's name with the average grade. Essentially, you're already doing this with your lists. Any time that you index two sequences (lists) to combine their data, you're effectively using a dictionary in a roundabout way:
The lists names and studentnames are redundant. I see that they're used for two different loops but lists can be reused. So, you could eliminate one of them and just use the other for both loops.
student_grades = { "Jane Doe": 99, "John Doe": 87, "Jane Doe II, electric boogaloo": 85 } # Returns 85. student_grades["Jane Doe II, electric boogaloo"] # Returns 85 or 0 if the entry doesn't exist. student_grades.get("Jane Doe II, electric boogaloo", 0) # Sets the value based on the key. # Also, Jane's parents are rad for giving her a subtitle. student_grades["Jane Doe II, electric boogaloo"] = 2525 # Returns 2525. student_grades["Jane Doe II, electric boogaloo"]Then, you can call calcGrade() at the end after retrieving the grade from the dictionary. This would have the added benefit of eliminating the lists "avg" and "grade". In fact, by changing that to a dictionary and changing the while loops to for loops, you can reduce the code by almost half.
The lists names and studentnames are redundant. I see that they're used for two different loops but lists can be reused. So, you could eliminate one of them and just use the other for both loops.