Question: Write a script that enables the user to enter mathematical word problems like Add two and three and Divide nine by three, then use

Write a script that enables the user to enter mathematical word problems

 

Write a script that enables the user to enter mathematical word problems like "Add two and three" and "Divide nine by three", then use string processing to break apart the string into the numbers and the operation and return the result. So "Add two and three" would return 5 and "Divide nine by three" would return 3. The user should enter only the words in lower case for the numbers 0 through 9 and specify the four mathematical operation in the following syntax: Add X and Y . Subtract X from Y Multiply X by Y Divide X by Y Please think about what data structure should be used to convert a numeral word to its correponding number. Please print an warning message, "Invalid Input", for the following exceptions in the input: Numbers outside the range of 0 to 9 Operations not in the specified syntax Division by zero Some examples are provided below: Please enter a math question: Multiply ten by two Invalid input! Please enter a math question: Multiply nine by two The answer is 18 Please enter a math question: Divide six by zero Invalid input! Please enter a math question: Divide six by three The answer is 2. Please enter a math question: Deduct three from five Invalid input! kernell Lidia

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!