Skip to content Skip to sidebar Skip to footer

Typeerror: Unsupported Operand Type(s) For +: 'int' And 'str' Error

Im having a problem with my code and it says TypeError: unsupported operand type(s) for +: 'int' and 'str' and i'm not sure why. the area of my code that causes this is shown be

Solution 1:

You explicitely take care that the things the user inputs are strings:

Score1 = str(input("what did the first person get in their test the first     time?"))

if you replace str() by int() or float() (depending on what you expect the input to be), your problem should go away, because you'd get a numeric type rather than a string.

Solution 2:

Cast the string by default input to an integer so that you can compute average scores:

Score1 = int(input("what did the first person get in their test the first time?"))

Solution 3:

You can also use map while calculating your score.

print ("here are the scores of",Name1,",well done") # defines scoresprint(P1S)
print ("here is the average score of",Name1,",Well Done") # makes average of  scoresprint(sum(map(int,P1S))/float(len(P1S)))

print ("here are the scores of",Name2,",well done") # defines scoresprint(P2S)
print ("here is the average score of",Name2,",Well Done") # makes average of scoresprint(sum(map(int,P2S))/float(len(P2S)))

print ("here are the scores of",Name3,",well done") # defines scoresprint(P3S)
print ("here is the average score of",Name3,",Well Done") # makes average of scoresprint(sum(map(int,P3S))/float(len(P3S)))

Also can you please tell how are you providing the inputs.

Post a Comment for "Typeerror: Unsupported Operand Type(s) For +: 'int' And 'str' Error"