I want to input "2 3" aiming to get a result of 5 but this doesn't work and I'm not really sure why.
a = input()
b = (a[0])
c = (a[2])
print (int(b)) + (int(c))
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
In python3, print()
is a function. You have to use it like: print(val)
. python2 used to use print val
, but python3 does not do this.
You need to do: print(int(b) + int(c))
In your code, you did: print (int(b)) + (int(c))
. You are doing print(val) + val
, and print()
doesn't return anything hence NoneType
+ int
.
print (int(b) + int(c))
instead