USE PYTHON Python already supports math, whereby you can write code to add, subtract, multiply, or divide values and even variables. But let’s write a program that enables users to do math, even without knowing Python. In a file called interpreter.py, implement a program that prompts the user for an arithmetic expression and then calculates and outputs the result as a floating-point value formatted to one decimal place. Assume that the user’s input will be formatted as x y z, with one space between x and y and one space between y and z, wherein: x is an integer y is +, -, *, or / z is an integer For instance, if the user inputs 1 + 1, your program should output 2.0. Assume that, if y is /, then z will not be 0. Note that, just as python itself is an interpreter for Python, so will your interpreter.py be an interpreter for math! Please see 2 attached photos for demo and Test program. **USE PYTHON** THANKS

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

USE PYTHON

Python already supports math, whereby you can write code to add, subtract, multiply, or divide values and even variables. But let’s write a program that enables users to do math, even without knowing Python.

In a file called interpreter.py, implement a program that prompts the user for an arithmetic expression and then calculates and outputs the result as a floating-point value formatted to one decimal place. Assume that the user’s input will be formatted as x y z, with one space between x and y and one space between y and z, wherein:

  • x is an integer
  • y is +, -, *, or /
  • z is an integer

For instance, if the user inputs 1 + 1, your program should output 2.0. Assume that, if y is /, then z will not be 0.

Note that, just as python itself is an interpreter for Python, so will your interpreter.py be an interpreter for math!

Please see 2 attached photos for demo and Test program.

**USE PYTHON**

THANKS

Demo
$ python interpreter.py
Expression: 1 + 1
2.0
$ python interpreter.py
Expression: 4 / 3
1.3
$ python interpreter.py
Expression: 100 - 1
99.0
Before You Begin
Transcribed Image Text:Demo $ python interpreter.py Expression: 1 + 1 2.0 $ python interpreter.py Expression: 4 / 3 1.3 $ python interpreter.py Expression: 100 - 1 99.0 Before You Begin
Here's
how to test your code manually:
• Run your program with python interpreter.py). Type 1 + 1 and press Enter. Your program should output:
2.0
• Run your program with python interpreter.py). Type 2 - 3 and press Enter. Your program should output:
-1.0
• Run your program with python interpreter.py. Type 2 * 2 and press Enter. Your program should output
4.0
• Run your program with python interpreter.py). Type 50 / 5 and press Enter. Your program should output
10.0
Transcribed Image Text:Here's how to test your code manually: • Run your program with python interpreter.py). Type 1 + 1 and press Enter. Your program should output: 2.0 • Run your program with python interpreter.py). Type 2 - 3 and press Enter. Your program should output: -1.0 • Run your program with python interpreter.py. Type 2 * 2 and press Enter. Your program should output 4.0 • Run your program with python interpreter.py). Type 50 / 5 and press Enter. Your program should output 10.0
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Constants and Variables
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
  • SEE MORE 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