Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Problem Statement 1/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions Problem Statement 2/README.md

This file was deleted.

11 changes: 1 addition & 10 deletions Problem Statement 3/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
# Problem Statement-3.


***
### Make a calculator with GUI



***

# calcalutor in python for GOC Hack2skill
95 changes: 95 additions & 0 deletions Problem Statement 3/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import sys
import math
## Imported math library to run sin(), cos(), tan() and other such functions in the calculator




def calc(term):
"""
input: term of type str
output: returns the result of the computed term.
purpose: This function is the actual calculator and the heart of the application
"""

# This part is for reading and converting arithmetic terms.
term = term.replace(' ', '')
term = term.replace('^', '**')
term = term.replace('=', '')
term = term.replace('?', '')
term = term.replace('%', '/100.00')
term = term.replace('rad', 'radians')
term = term.replace('mod', '%')
term = term.replace('aval', 'abs')

functions = ['sin', 'cos', 'tan', 'pow', 'cosh', 'sinh', 'tanh', 'sqrt', 'pi', 'radians', 'e']

# This part is for reading and converting function expressions.
term = term.lower()

for func in functions:
if func in term:
withmath = 'math.' + func
term = term.replace(func, withmath)

try:

# here goes the actual evaluating.
term = eval(term)

# here goes to the error cases.
except ZeroDivisionError:

print("Can't divide by 0. Please try again.")

except NameError:

print('Invalid input. Please try again')

except AttributeError:

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

except Exception:
print("Wrong operator")

return term


def result(term):
"""
input: term of type str
output: none
purpose: passes the argument to the function calc(...) and
prints the result onto console.
"""
print("\n" + str(calc(term)))


def main():
"""
main-program
purpose: handles user input and prints
information to the console.
"""


if sys.version_info.major >= 3:
while True:
k = input("\nWhat is ")
if k == 'quit':
break
result(k)

else:
while True:
k = raw_input("\nWhat is ")
if k == 'quit':
break
result(k)


if __name__ == '__main__':
main()
66 changes: 0 additions & 66 deletions README.md

This file was deleted.