H. Seigne H. Seigne - 1 year ago 60
Python Question

New to programming and trying to finish this task for school, I can't seem to add numbers in a list together

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:
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: ")
judgeScoreForLoop + 1
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


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download