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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education