Solve via WolframAlpha (Python 3.3.x) 06-10-2014, 03:33 PM
#1
Required imports:
Functions:
Example Usage:
Example Output:
Revision 0: Initial release.
Revision 1: Added support for the 'pi' character.
Code:
from urllib import parse, request
from html.parser import HTMLParserFunctions:
Code:
def wolfram(problem):
aurl = "http://www.wolframalpha.com/input/?i=" + parse.quote_plus(problem)
data = str(request.urlopen(aurl).read(), encoding="utf-8")
return wolfram_fix(data.split("\"stringified\": \"")[2].split("\"")[0])
def wolfram_fix(data):
return HTMLParser().unescape(data).replace("\\/", "/").replace("pi", u"\u03c0")Example Usage:
Code:
def main():
while True:
problem = input("Enter a problem to solve: ")
print(wolfram(problem))Example Output:
Code:
Enter a problem to solve: solve 5x+3=3 for x
x = 0
Enter a problem to solve: solve 8x^2+5=10 for x
x = ±sqrt(5/2)/2 ~~ ±0.79057
Enter a problem to solve: solve 5*x=pi for x
x = π/5 ~~ 0.62832Revision 0: Initial release.
Revision 1: Added support for the 'pi' character.
![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)







![[+]](https://sinister.li/images/modern/collapse_collapsed.png)


Honestly didn't think of this before