Skip to content

Commit 534ee02

Browse files
author
dareghost
authored
Update calculator.py
did error handling for type error when the user gives an input of incorrect datatype and added the exponents function
1 parent b300b4c commit 534ee02

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

calculator.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
pi : 3.141592...
1515
sine : sin(rad)
1616
cosine : cos(rad)
17+
exponent: x^y
1718
tangent : tan(rad)
1819
remainder : XmodY
1920
square root : sqrt(n)
@@ -37,11 +38,11 @@ def calc(term):
3738
term = term.replace('^', '**')
3839
term = term.replace('=', '')
3940
term = term.replace('?', '')
40-
term = term.replace('%', '/100')
41+
term = term.replace('%', '/100.00')
4142
term = term.replace('rad', 'radians')
4243
term = term.replace('mod', '%')
4344

44-
functions = ['sin', 'cos', 'tan', 'cosh', 'sinh', 'tanh', 'sqrt', 'pi', 'radians', 'e']
45+
functions = ['sin', 'cos', 'tan','pow', 'cosh', 'sinh', 'tanh', 'sqrt', 'pi', 'radians', 'e']
4546

4647
# This part is for reading and converting function expressions.
4748
term = term.lower()
@@ -68,6 +69,8 @@ def calc(term):
6869
except AttributeError:
6970

7071
print('Please check usage method and try again.')
72+
except TypeError :
73+
print ("please enter inputs of correct datatype ")
7174

7275
return term
7376

0 commit comments

Comments
 (0)