This is what I have so far:
import sys
first = float(sys.argv[1])
second = str(sys.argv[2])
third = float(sys.argv[3])
if second == "+":
print first + third
elif second == "-":
print first - third
elif second == "*":
print first * third
elif second == "/":
print first / third
elif second == "^":
print first ** third
else:
print "Invalid Operator"
The first and third arguments are supposed to be double floating point numbers. I wasn't sure how the operator is supposed to be represented, so I just named it "second" and set it as a string. I'm confused as to how I'm supposed to actually get the calculations. Are my if/elif/else statements wrong? Am I supposed to use "print" or "return" for actual calculations to be made?
This is an example of a test file:
def test_add(self):
output = self.runScript("simple_calc.py", "1", "+", "1")
result = float(output)
self.assertAlmostEqual(2.0, result, places=10)
output = self.runScript("simple_calc.py", "-1", "+", "1")
result = float(output)
self.assertAlmostEqual(0.0, result, places=10)
output = self.runScript("simple_calc.py", "1.0", "+", "-1.0")
result = float(output)
self.assertAlmostEqual(0.0, result, places=10)