Question: In python please create a tiny interpreter for simple arithmetic operations. Your program will read it input from a file containing one command per line

In python please create a tiny interpreter for simple arithmetic operations. Your program will read it input from a file containing one command per line and it will write its output to a second file. Please include screenshots of outputs.

Specifications:

1. Your program must ask the user for the names of both files. If there are problems with either file (inaccessible, unwritable, etc.) your program should complain and request file names again.

2. Your program should append .txt to a file name if it does not already have a .txt suffix.

3. The commands will look like this: operation value1 value2. See the Commands.txt file for details. If the input file does not exist or the output file is not writable the program must complain and ask the user for alternative file name(s).

4. The operations are add, sub, multiply, divide, and power. The commands are not case-sensitive. The values must be integers.

5. An empty line should be silently ignored.

6. Your program must read the commands from the input file one at a time, interpret them, and write results into the output file. Your program must stop when it reaches the end of the input file.

7. Your program must use exception handling to deal with exceptions such as divide-by- zero and improperly formed inputs (commands and values).

8. For your final submission your program must be run at least twice. Use Commands.txt for one run. Create at least one other input file for your other run(s).

9. Your submission must include your Python program, the input files, the output files, and your screen captures. Dont do a screen capture of the input or output files just provide them when you submit.

Run your program several times using different inputs sufficient to demonstrate that your program meets all the assignment requirements.

File commands.txt contains:

add 11 22 DIVIDE 99 11 Multiply 22 10001 power 11 22 sub 2 101 divide 7 0 Power 2 10 ADD 123 45.67 multiply -3 -7 bad 1 2 power 10 -2 Fail sub 1001 1700

Sample Output

In python please create a tiny interpreter for simple arithmetic operations. Your

O: Ci. CilWindowstsystem321 cmdiexe Command Processor Name of input file: no such file Name of output file: output.txt Input file: no such file.txt Output file: output.txt Operation failed: No such file or directory Wame of input file: commands Name of output file: output Input file: commands.txt Output file: output.txt Done! Contents of Commands.txt add 1122 DIVIDE 9911 Multiply 2210001 Contents of Output.xt Interpreter Runtime Output 1:add(11,22)=33 2:divide(99,11)=9.0 3: multiply (22,10001)=220,022

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 Databases Questions!