-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBasicCalculator.py
36 lines (32 loc) · 1.03 KB
/
BasicCalculator.py
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
# Author:
# Agyeya Mishra
# Department of Civil Engineering
# Delhi Technological University (formerly, Delhi College of Engineering)
# New Delhi, India
import sys
from Functions import *
#Python program to create a simple calculator
for line in sys.stdin:
line = line.rstrip()
if '+' in line:
nums = line.split('+')
print(add(int(nums[0]), int(nums[1])))
elif '-' in line:
nums = line.split('-')
print(subtract(int(nums[0]), int(nums[1])))
elif '*' in line:
nums = line.split('*')
print(multiply(int(nums[0]), int(nums[1])))
elif '/' in line:
nums = line.split('/')
print(divide(int(nums[0]), int(nums[1])))
elif '%' in line:
nums = line.split('%')
print(mod(int(nums[0]), int(nums[1])))
elif '^' in line:
nums = line.split('^')
print(exponent(int(nums[0]), int(nums[1])))
elif line == "quit" or line == "exit":
exit()
else:
print("This mathematical expression is either wrong or not supported.")