On Fri, Aug 28, 2009 at 2:35 PM, Ben Finney
<[email protected]<ben%[email protected]>
> wrote:
> import operator
>
> op_funcs = {
> '+': operator.add,
> '-': operator.sub,
> '*': operator.mul,
> '/': operator.div,
> }
>
> num_1 = int(raw_input('Enter the first number: '))
> num_2 = int(raw_input('Enter the second number: '))
> op_prompt = "Select an operator ({}):".format(','.join(op for op in
> op_funcs))
>
op_symbol = raw_input(op_prompt)
> op_func = op_funcs[op_symbol]
> print 'The answer is: ', op_func(num_1, num_2)
Just fixing the code a little to be more "Pythonic" ;).
Might also want to do exception handling, but with a program this small,
meh.
--
http://mail.python.org/mailman/listinfo/python-list