"""
Parse and evaluate simple math word problems returning the answer as an integer.
"""defanswer(question:str)->int:replacements={"What is":"","plus":"+","minus":"-","multiplied by":"*","divided by":"/","?":""}forword,symbolinreplacements.items():question=question.replace(word,symbol)tokens=question.split()tokens.insert(0,"(")tokens.insert(4,")")iflen(tokens)<3:raiseValueError("syntax error")ifany(token.isalpha()andtokennotinlist(replacements.keys())fortokenintokens):raiseValueError("unknown operation")try:returneval("".join(tokens))except:raiseValueError("syntax error")