View Single Post
Old Feb 8th, 2006, 1:33 AM   #12
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by DaWei
What does that mean? Replace the arithmetic operator with a function?
He probably means something like:
from operator import add, sub, mul, div
operators = { '+' : add, '-' : sub, '*' : mul, '/' : div }

op = raw_input("Please enter the prefered operator: +, -, *, /")

a = int(raw_input("Please enter a number:"))
b = int(raw_input("Please enter another number:"))
print "Answer = " + operators[op](a, b)
Arevos is offline   Reply With Quote