File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1818"""
1919
2020import math
21+ import sys
22+
2123
2224def main ():
2325
@@ -33,26 +35,28 @@ def calc(k):
3335 try :
3436 k = eval (k )
3537 except ZeroDivisionError :
36- print ("Can't divide by 0" )
38+ print ("Can't divide by 0" )
3739 exit ()
3840 except NameError :
39- print ( " Invalid input" )
41+ print ( ' Invalid input' )
4042 exit ()
4143
4244 return k
4345
46+ print ("\n Scientific Calculator\n Eg: pi * sin(90) - sqrt(81)" )
4447
45- print ("\n Scientific Calculator\n Eg: pi * sin(90) - sqrt(81)" )
46-
47- k = raw_input ("\n What is " ) # Using input() function is causing NameError. Changing it to raw_input() fixes this.
48+ if sys .version_info .major >= 3 :
49+ k = input ("\n What is " )
50+ else :
51+ k = raw_input ("\n What is " )
4852
4953 k = k .replace (' ' , '' )
5054 k = k .replace ('^' , '**' )
5155 k = k .replace ('=' , '' )
5256 k = k .replace ('?' , '' )
5357 k = k .replace ('%' , '/100' )
5458
55- print ("\n " + str (calc (k )))
59+ print ("\n " + str (calc (k )))
5660
57- if __name__ == " __main__" :
61+ if __name__ == ' __main__' :
5862 main ()
You can’t perform that action at this time.
0 commit comments