Python Forum
Student grade program help debug
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Student grade program help debug
#4
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:

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


Messages In This Thread
Student grade program help debug - by ccm1776 - Nov-12-2018, 05:29 PM
RE: Student grade program help debug - by ccm1776 - Nov-12-2018, 06:50 PM
RE: Student grade program help debug - by stullis - Nov-14-2018, 02:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Method to calculate average and grade ajitnayak1987 8 6,563 Apr-28-2022, 06:26 AM
Last Post: rayansaqer
  Student project - alert action when X happens Y amt of times, how? unknown00 2 1,906 Aug-25-2021, 08:07 PM
Last Post: namarang
  Non Grade/School Help - PLEASE gbyrne12 8 3,267 Jun-19-2021, 07:31 PM
Last Post: snippsat
  Student grader and sorter for assignment RazeAD 7 3,334 Feb-11-2021, 06:29 AM
Last Post: RazeAD
Sad [split] HELP ME DEBUG - Who wants to be a millionaire Game Beetoh 1 2,157 Dec-18-2020, 06:09 PM
Last Post: buran
  Generating a student's transcript [OOP concept] aongkeko 2 2,817 Dec-01-2020, 06:43 AM
Last Post: buran
  Create code for input names and score for 15 student Davin 2 2,190 Sep-21-2020, 08:49 AM
Last Post: DeaD_EyE
  New Python Student = Does this code look right? musicjoeyoung 6 3,606 May-07-2020, 02:39 PM
Last Post: musicjoeyoung
  Calculating Grade Average IstvanCH 5 5,296 Jan-27-2019, 04:42 PM
Last Post: aakashjha001
  Grade Loop dtweaponx 8 12,633 Oct-17-2017, 02:01 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020