Quote:
Originally Posted by zorocke
I am wondering what your code looks like because I am still very unfamiliar with Python. Do you think you could post those 10 lines? 
|
Sure, always glad to help a new pythonist.
Code:
#!/usr/bin/python
import re #Import the regular expression module
pat = re.compile('\d+ *[+\-*\/] *\d+') #Set up the Regex pattern for a math problem
prob = raw_input() #Get the problem
if pat.match(prob):
print eval(prob) #Print the evaluated problem, but only if it matches the pattern
else:
print "Invalid math problem" #If it doesn't, then it isn't a math problem
But if you reduce it to the absolute minimum, you can do it in one line!