Are you sure you are using Python 3? In python 2.x you can do it by explictly evaluating an string expression with the eval()
function:
c = eval(raw_input()) # Python 2.7
c = eval(input()) # Python 3.x
In Python 3.x input()
will convert the input in a string and won't raise that error (NameError
). It will raise a TypeError
instead, because you cannot concatenate str
and int
that way.