Beginner in python, but been programming for about 5 years now. I suspect I have a lot to learn about doing things the object oriented way, but I know the basics. I planned on programming a calculator that shows it s work for the challenge and knowledge i ll gain from it. I just started and this is what i ve got, and it just looks really ugly to me. How would you have done it differently?
P.S. This is just a simple script to take the problem from inside parenthesis, add it up, show the work, then evaluate the full problem.
import re
def EvalParenths(problem):
contents = ""
if re.match( "(", problem):
contents = re.match("((.*))", problem)
parenthsAnswer = contents.group(0)
problem = problem.replace(parenthsAnswer, )
print "
" + str(eval(parenthsAnswer)) + problem
problem = problem.replace(parenthsAnswer, )
answer = eval(parenthsAnswer+problem)
print "
" + str(answer)
else:
print "Didn t Find Parenthesis"
def ProblemHasParenths(problem):
return re.match( "(", problem)
"""""
Example Problem: (12/4)*2
"""""
problem = raw_input()
if ProblemHasParenths:
EvalParenths(problem)