Please help Using python Interpreter In this exercise you will 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. 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). comends.txt 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 Contents of Commands.txt add 11 22 DIVIDE 99 11 Multiply 22 10001 ... Contents of Output.xt Interpreter Runtime Output 1 : add(11,22) = 33 2 : divide(99,11) = 9.0 3 : multiply(22,10001) = 220,022 Sample Output: 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 Name of input file: commands Name of output file: output Input file: commands.txt output file: output.txt
Please help Using python Interpreter In this exercise you will create a tiny interpreter for simple arithmetic operations. Your
comends.txt
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
Contents of Commands.txt
add 11 22
DIVIDE 99 11
Multiply 22 10001 ...
Contents of Output.xt
Interpreter Runtime Output 1 :
add(11,22) = 33 2 :
divide(99,11) = 9.0 3 :
multiply(22,10001) = 220,022
Sample Output:
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
Name of input file: commands
Name of output file: output
Input file: commands.txt
output file: output.txt
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images