0

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'

1
  • 2
    try print (int(b) + int(c)) instead
    – qouify
    Commented Apr 20, 2021 at 15:36

1 Answer 1

2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.