1

I have a bit of code thats for a task we have to complete for school. I'm trying to add some numbers in a list so I can average that number. Whenever I try to do this it just tells me its an unsupported operand type for int and str. I think what I have to do is convert the inputs into floats rather than strings but I'm not sure how to. Code below:

final = False
while final == False: 
    judgeScoreForLoop = 0
    judgeScoreLoop = []

    while True:
        try:
            eventName = str(input("What is the event's name? "))
            numberJudges = int(input("How many judges are there? "))
            competitorName = str(input("What is the competitor's name? "))
            for judgeScoreForLoop in range (0, numberJudges):
                judgeScore = input("Enter the judge score here: ")
                judgeScoreLoop.append(judgeScore)
                judgeScoreForLoop + 1
            break
        except ValueError:
            print("One of the inputs was invalid, please try again.")

    finalJudges = numberJudges - 2

    judgeScoreCombined = sum(judgeScoreLoop)
    judgeFinalScore = judgeScoreCombined / finalJudges

    if competitorName == "Finish".lower():
        final = True

    print(judgeFinalScore)
H. Seigne
  • 45
  • 4
  • 1
    inputs are strings by default; what you need to do is convert the `judgeScore` values to integers (or floats) before appending them to the list – Hamms Jun 11 '16 at 00:30
  • Also, side-note, `judgeScoreForLoop + 1` is pointless; your loop is already incrementing it, and even if it weren't, you never assigned the result of the addition, so it just gets thrown away. – ShadowRanger Jun 11 '16 at 00:38
  • Note that the `input()` function is different between Python 2 and Python 3. It would be useful to add which one you're using. Ex. http://stackoverflow.com/questions/3800846/differences-between-input-and-raw-input – Taylor D. Edmiston Jun 11 '16 at 01:06

1 Answers1

3

You can convert the input straight into a float

  judgeScore = float(input("Enter the judge score here: "))

But it might be best to check if the user has supplied a number first by prehaps using isdigit() I don't want to give too much away but that should help

Dave Norm
  • 185
  • 8