Search code examples
pythonfunctionsumreturnstore

Using returned outputs from one function in another in Python


new to Python - struggling with functions. - Image of code attached.

It inputs the name & scores just fine with the validation checks. I need to use the scores input by the user and total them. However, when I've tried to sum(score) it doesn't like it. I can't work out how to sum the 4 total scores.

Please help :) Also would love any feedback on the style of coding etc. Thanks in advance x

Image: Code in Python


Solution

  • I would rewrite the main function to be something like:

    def GetStudentInput():
      score = 0
      for i in range (4):
          print("Mrs Pearson's Class Test Score Data")
          name = CheckStringInput("What's Your Name: ")
          score += CheckNumericInput("What's Your Score: ")
      print(score)
    

    This eliminates the need for an extra function and avoids using a list since you don't appear to need the individual values elsewhere -- only the sum total.