TypeError: unsupported operand type(s) for +: 'int' and 'str' error

后端 未结 3 1580
灰色年华
灰色年华 2020-12-04 03:10

Im having a problem with my code and it says

TypeError: unsupported operand type(s) for +: \'int\' and \'str\'

and i\'m not sur

相关标签:
3条回答
  • 2020-12-04 04:08

    You can also use map while calculating your score.

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

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

    0 讨论(0)
  • 2020-12-04 04:15

    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?"))
    
    0 讨论(0)
  • 2020-12-04 04:17

    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.

    0 讨论(0)
提交回复
热议问题