A simple calculator
This commit is contained in:
parent
a7aabeaf49
commit
025016ab56
|
|
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue