title: How to calculate a grade for a class using lists and functions in Python
body: <p>I need to write a program that calculates a grade for a class based on the following input and processes:</p>
  
  <ol>
  <li><p>Ask the user for the number of tests, assignments, quizzes, and labs in their course.</p></li>
  <li><p>Ask the user if there is a final with a separate weight from the tests above, e.g. a course has 2 tests, each weighing 12.5%, and 1 final weighing 15%.</p></li>
  <li><p>For each category having a number > 0 a. Prompt the user for the weighted percent, out of 100%, which should total 100% for all categories!!! b. Get the score(s) for the category. c. If the category is labs, then sum all the scores. d. Else, average the scores. e. Calculate the weighted average for the category. </p></li>
  <li><p>Using the weighted average of each category, calculate the grade in the course.</p></li>
  <li><p>Ask the user if he/she wants to calculate a grade for another class.</p></li>
  <li><p>If the user responds yes, then go back to step 1. 7. Else, end the program.</p></li>
  </ol>
  
  <p>I am almost finished with the program and have all of my functions but I am having difficulty making it all come together and work properly. My first problem is incorporating steps 5/6 and getting the while loop to work with the rest of the code. Additionally, I am having difficulty summing the lab scores and incorporating that value into the weighted average.</p>
  
  <p>Any help is much appreciated!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def main():
         inputList = get_user_input()
         average = get_scores(inputList)
         weightedAvgs = get_weightedavg(average, inputList)
         results = get_class_grade(weightedAvgs)
  
         ans = "yes"
         while(ans == "yes"):
              def get_user_input():
                      inputList = [] # initializes a list
              # Gets how many scores for each category the user would like to enter and adds value to a list
                      tests = int(input("How many tests scores would you like to enter? "))
                      inputList.append(tests)
                      assignments = int(input("How many assignment scores would you like to enter: "))
                      inputList.append(assignments)
                      quizzes = int(input("How many quiz scores would you like to enter? "))
                      inputList.append(quizzes)
                      labs = int(input("How many lab scores would you like to enter? "))
                      inputList.append(labs)
                      final = int(input("How many final scores would you like to enter? "))
                      inputList.append(final)
  
              # Gets the weight of each category if there are any scores to enter and adds the value to a list
                      if tests &gt; 0:
                              testWeight = float(input("Enter the weight of tests: "))
                              inputList.append(testWeight)
                      else:
                              testWeight = 0
                      if assignments &gt; 0:
                              assignmentWeight = float(input("Enter the weight of assignments: "))
                              inputList.append(assignmentWeight)
                      else:
                              assignmentWeight = 0
                      if quizzes &gt; 0:
                              quizWeight = float(input("Enter the weight of quizzes: "))
                              inputList.append(assignmentWeight)
                      else:
                              quizWeight = 0
                      if labs &gt; 0:
                              labWeight = float(input("Enter the weight of labs: "))
                              inputList.append(labWeight)
                      else:
                              labWeight = 0
                      if final &gt; 0:
                              finalWeight = float(input("Enter the weight of the final: "))
                              inputList.append(finalWeight)
                      else:
                              finalWeight = 0
  
                      return(inputList)
  
              def get_scores(inputList):
              # Gets scores for each category &amp; calculates avg for each category
                      average = []
                      testScoreList = []
                      tests2 = inputList[0]
                      for x in range(tests2):
                              testScore = float(input("Enter your test score: "))
                              testScoreList.append(testScore)
                      if tests2 == 0:
                              testAvg = 0
                      else:
                              testAvg = sum(testScoreList) / inputList[0]
                      average.append(testAvg)
  
  
                      assignmentScoreList = []
                      assignments2 = inputList[1]
                      for x in range(assignments2):
                              assignmentScore = float(input("Enter your assignment score: "))
                              assignmentScoreList.append(assignmentScore)
                      if assignments2 == 0:
                              assignmentAvg = 0
                      else:
                              assignmentAvg = sum(assignmentScoreList) / inputList[1]
                      average.append(assignmentAvg)
  
  
                      quizScoreList = []
                      quizzes2 = inputList[2]
                      for x in range(quizzes2):
                              quizScore = float(input("Enter your quiz score: "))
                              quizScoreList.append(quizScore)
                      if quizzes2 == 0:
                              quizAvg = 0
                      else:
                              quizAvg = sum(quizScoreList) / inputList [2]
                      average.append(quizAvg)
  
  
                      labScoreList = []
                      labs2 = inputList[3]
                      for x in range(labs2):
                              labScore = float(input("Enter your lab score: "))
                              labScoreList.append(labScore)
                      if labs2 == 0:
                              labSum = 0
                      else:
                              labSum = sum(labScoreList)
                      average.append(labSum)
  
  
                      finalScoreList = []
                      final2 = inputList[4]
                      for x in range(final2):
                              finalScore = float(input("Enter the score for your final: "))
                              finalScoreList.append(finalScore)
                      if final2 == 0:
                              finalAvg = 0
                      else:
                              finalAvg = sum(finalScoreList) / inputList[4]
                      average.append(finalAvg)
  
  
              def get_weighted_avg(average, inputList):
                      weightedAvgs = []
  
                      weightedTestAvg = average[0] * inputList[5]
                      weightedAvgs.append(weightedTestAvg)
                      print("Your weighted average is " + str(weightedTestAvg))
  
                      weightedAssignmentAvg = average[1] * inputList[6]
                      weightedAvgs.append(weightedAssignmentAvg)
                      print("Your weighted average is " + str(weightedAssignmentAvg))
  
                      weightedQuizAvg = average[2] * inputList[7]
                      weightedAvgs.append(weightedQuizAvg)
                      print("Your weighted average is " + str(weightedAssignmentAvg))
  
                      weightedLabSum = average[3] * inputList[8]
                      weightedAvgs.append(weightedLabSum)
                      print("The sum of your lab scores are " + str(weightedLabAvg))
  
                      weightedFinalAvg = average[4] * inputList[9]
                      weightedAvgs.append(weightedFinalAvg)
                      print("Your weighted average is " + str(weightedFinalAvg))
  
                      return(weightedAvgs)
  
              def get_class_grade(weightedAvgs):
                      grade = weightedAvgs[0] + weightedAvgs[1] + weightedAvgs[2] + weightedAvgs[3] + weightedAvgs[4]
  
                      if grade &gt;= 90:
              finalGrade = "A"
                      elif grade &gt;= 80:
                              finalGrade = "B"
                      elif grade &gt;= 70:
                              finalGrade = "C"
                      elif grade &gt;= 60:
                              finalGrade = "D"
                      else:
                              finalGrade = "F"
  
                      print("Your grade is " + finalGrade)
                      ans = (input("Would you like to calculate a grade for another class? "))
                      while(ans != "yes" and ans != "no"):
                              print("Please type yes or no")
                              ans = (input("Would you like to calculate a grade for another class? "))
      if ans == "no":
              exit()
  main()
  </code></pre>