From 025016ab56e9a1cca7aa4013a32c372376edc1ff Mon Sep 17 00:00:00 2001 From: Abhay Date: Mon, 28 Oct 2019 14:37:45 +0530 Subject: [PATCH] A simple calculator --- SimpleCalculator.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 SimpleCalculator.py diff --git a/SimpleCalculator.py b/SimpleCalculator.py new file mode 100644 index 0000000..8131924 --- /dev/null +++ b/SimpleCalculator.py @@ -0,0 +1,21 @@ +print("""this is a simple calcultor that accepts equations that are seperated by spaces in between operators and operands: + for example: 2 + 3. It does not accept more than one operator """) +equation = input("").split() +res = 0 +if '/' in equation: + n = equation.index('/') + res+=int(equation[n-1])/int(equation[n+1]) +elif '*' in equation: + n = equation.index('*') + res+=int(equation[n-1])*int(equation[n+1]) +elif '+' in equation: + n = equation.index('+') + res+=int(equation[n-1])+int(equation[n+1]) +elif '-' in equation: + n = equation.index('-') + res+=int(equation[n-1])-int(equation[n+1]) +else: + print("Please give the sum in a valid format with spaces.") +print(res) + +