Reputation: 45
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)
Upvotes: 1
Views: 85
Reputation: 185
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
Upvotes: 3