forked from sureshb208/Beginners-Python-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
36 lines (31 loc) · 1.18 KB
/
Copy pathcalculator.py
File metadata and controls
36 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
# Functions to apply basic arithmetic
# operations on 2 numbers
# Each func, takes 2 numbers as input
add = lambda a, b: a + b
subtract = lambda a, b: a - b
multiply = lambda a, b: a * b
divide = lambda a, b: a / b
modulus = lambda a, b: a % b
# CLI
# Testing/Playing Interface
i = 0
while True:
if raw_input("\n\n[{}] Exit(press e) or Calculate(press c): ".format(i)) == "c":
op = raw_input("\nAdd(press a), Subtract(press s), Multiply(press m),\nDivide(press d), Modulus(press mo): ").strip().lower()
if op == "a":
print(" Sum: " + str(add(float(raw_input("\nN1: ")), float(raw_input("N2: ")))))
elif op == "s":
print(" Subtracted: " + str(subtract(float(raw_input("\nN1: ")), float(raw_input("N2: ")))))
elif op == "m":
print(" Multiplied: " + str(multiply(float(raw_input("\nN1: ")), float(raw_input("N2: ")))))
elif op == "d":
print(" Divided: " + str(divide(float(raw_input("\nN1: ")), float(raw_input("N2: ")))))
else:
print(" Modulus: " + str(modulus(float(raw_input("\nN1: ")), float(raw_input("N2: ")))))
i += 1
else:
print("\nHope you enjoyed!")
sys.exit()