num= [30, 29, 47, 10, 78]
a = input ("What number do you want to add?") #Accept a number to add
num.append(a) # Add accepted numbers using append among methods
plus = sum(num)
average = plus / len(num)
print(average)
If I input it, the number I received is added to the list, but after that, the error appears like this. Where and how should I fix it?
TypeError Traceback (most recent call last)
<ipython-input-17-b5963e133a37> in <module>()
2 a = input ("Number to add?") #Accept a number to add
3 num.append(a) # Add accepted numbers using append among methods
----> 4 plus = sum(num)
5 average = plus / len(num)
6 print(average)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
input returns str object.
Please convert to int object.
b = []
a = input()
print(type(a))
>> <type 'str'>
b.append(int(a))
© 2024 OneMinuteCode. All rights reserved.