<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">num1 = raw_input('Enter the first number: ')<br>
num2 = raw_input('Enter the second number: ')<br>
op = raw_input('Select one of the following [+-*/]: ')<br>
print 'The answer is: ', int(num1), eval(op), int(num2)<br>
                                    ^^^^^^^^<br>
<br>
How do I convert the contents of "op" from a string to an actual<br>
arithmetic operator? eval() does not seem to be the answer. TIA!<br>
</blockquote><div><br></div><div>You could eval(num1+op+num2), but it'd be safer to do:</div><div><br></div><div>import operator</div><div>operators = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.div}</div>

<div>fn = operators[op]</div><div>print "The answer is:", fn(int(num1), int(num2))</div><div><br></div><div>Its best to avoid eval when possible :)</div><div><br></div><div>--S</div></div>