Skip to content

Commit 3267d2f

Browse files
author
Karan Goel
committed
Calculator done
1 parent 7ac7c03 commit 3267d2f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Numbers/calc.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: cp1252 -*-
2+
"""
3+
Calculator – A simple calculator to do basic operators.
4+
"""
5+
6+
if __name__ == '__main__':
7+
num1 = input("Number 1: ")
8+
num2 = input("Number 2: ")
9+
op = raw_input("Operation (+, -, /, *): ")
10+
11+
if op not in '+-/*':
12+
print "Invalid operator"
13+
else:
14+
if op == '+':
15+
res = num1 + num2
16+
elif op == '-':
17+
res = num1 - num2
18+
elif op == '/':
19+
res = num1 / num2
20+
elif op == '*':
21+
res = num1 * num2
22+
print "%d %s %d = %d" % (num1, op, num2, res)

0 commit comments

Comments
 (0)