← Projects

Calculator done

3267d2f0a06eaa51b7823cc398e86b16254537d9 · Karan Goel · Jul 8, 2013 16:48

+22 · 1 file changed

  • Numbers/calc.py +22 −0
diff --git a/Numbers/calc.py b/Numbers/calc.py
new file mode 100644
index 0000000..3d8dd66
--- /dev/null
+++ b/Numbers/calc.py
@@ -0,0 +1,22 @@
+# -*- coding: cp1252 -*-
+"""
+Calculator  A simple calculator to do basic operators.
+"""
+
+if __name__ == '__main__':
+    num1 = input("Number 1: ")
+    num2 = input("Number 2: ")
+    op = raw_input("Operation (+, -, /, *): ")
+
+    if op not in '+-/*':
+        print "Invalid operator"
+    else:
+        if op == '+':
+            res = num1 + num2
+        elif op == '-':
+            res = num1 - num2
+        elif op == '/':
+            res = num1 / num2
+        elif op == '*':
+            res = num1 * num2
+        print "%d %s %d = %d" % (num1, op, num2, res)