Hi all, absolute Python beginner here...
Question: I am getting an "unsupported operand type" error on my code below on line 13 of my code. I think it's telling me I need to cast from a string to an integer but everything I try I still get an error.
Can anyone please tell me what i'm missing/doing wrong?
please enter your 5 marks below
enter mark 1: 10
enter mark 2: 12
enter mark 3: 16
enter mark 4: 14
enter mark 5: 18
['10', '12', '16', '14', '18']
CODE
Thanks,
Aaron
Question: I am getting an "unsupported operand type" error on my code below on line 13 of my code. I think it's telling me I need to cast from a string to an integer but everything I try I still get an error.
Can anyone please tell me what i'm missing/doing wrong?
Error:Traceback (most recent call last):
File "C:/Users/aaron/PycharmProjects/assessment_two/marks.py", line 13, in <module>
sumOfMarks = sum(marksList)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
ERRORplease enter your 5 marks below
enter mark 1: 10
enter mark 2: 12
enter mark 3: 16
enter mark 4: 14
enter mark 5: 18
['10', '12', '16', '14', '18']
Error:Traceback (most recent call last):
File "C:/Users/aaron/PycharmProjects/assessment_two/marks.py", line 13, in <module>
sumOfMarks = sum(marksList)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Process finished with exit code 1CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
print ( "please enter your 5 marks below" ) mark1 = input ( "enter mark 1: " ) mark2 = input ( "enter mark 2: " ) mark3 = input ( "enter mark 3: " ) mark4 = input ( "enter mark 4: " ) mark5 = input ( "enter mark 5: " ) marksList = [mark1, mark2, mark3, mark4, mark5] print (marksList) sumOfMarks = sum (marksList) averageOfMarks = sum (marksList) / 5 print ( "The sum of your marks is: " + str (sumOfMarks)) print ( "The average of your marks is: " + str (averageOfMarks)) |
Aaron