Elias Haroun
Published © MIT

Mathy: The math teacher

Alexa will be the maths tutor for students of all ages. This skill will help students do all math operations from simple to complex math.

BeginnerWork in progress3 hours534
Mathy: The math teacher

Things used in this project


Read more


System diagram


Alexa Skill - AWS Lambda

import urllib
import urllib2
import re
import json

def lambda_handler(event, context):
    if (event['session']['application']['applicationId'] != "amzn1.ask.skill.dae3422d-d32d-xxxx-xxxx-e2dc1986608e"):
        raise ValueError("Invalid Application ID")
    url = 'http://api.wolframalpha.com/v2/query'
    values = {'appid' : 'XXXXXX-XXXXXXXXXX',
              'input' : event['request']['intent']['slots']['Problem']['value']}
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    response = response.read()
    response = str(re.findall(r'<plaintext>(.*)?</plaintext>', response))
    session_attributes = {}
    card_title = "Alexa My Math Teacher"
    speech_output = "The answer is " + response
    reprompt_text = ""
    should_end_session = True
    return build_response(session_attributes, build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session)) 
def build_speechlet_response(title, output, reprompt_text, should_end_session):
    return {
        "outputSpeech": {
            "type": "PlainText",
            "text": output
        "card": {
            "type": "Simple",
            "title": title,
            "content": output
        "reprompt": {
            "outputSpeech": {
                "type": "PlainText",
                "text": reprompt_text
        "shouldEndSession": should_end_session

def build_response(session_attributes, speechlet_response):
    return {
        "version": "1.0",
        "sessionAttributes": session_attributes,
        "response": speechlet_response


Elias Haroun

Elias Haroun

1 project • 1 follower
Computer science student, fascinated by AI, ML, and NLP