1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Stolb23 [73]
3 years ago
6

Write a program that prompts the user to enter an equation in the form of 10 5, or 10-5, or 1*5, or 13/4, or 13%4. The program s

hould then output the equation, followed by an equal sign, and followed by the answer.
Computers and Technology
1 answer:
grandymaker [24]3 years ago
5 0

Answer:

  1. equation = input("Enter an equation: ")
  2. if("+" in equation):
  3.    operands = equation.split("+")
  4.    result = int(operands [0]) + int(operands[1])
  5.    print(operands[0] + "+" + operands[1] + "=" + str(result))
  6. elif("-" in equation):
  7.    operands = equation.split("-")
  8.    result= int(operands [0]) - int(operands[1])
  9.    print(operands[0] + "-" + operands[1] + "=" + str(result))  
  10. elif("*" in equation):
  11.    operands = equation.split("*")
  12.    result = int(operands [0]) * int(operands[1])
  13.    print(operands[0] + "*" + operands[1] + "=" + str(result))  
  14. elif("/" in equation):
  15.    operands = equation.split("/")
  16.    result = int(operands [0]) / int(operands[1])
  17.    print(operands[0] + "/" + operands[1] + "=" + str(result))  
  18. elif("%" in equation):
  19.    operands = equation.split("%")
  20.    result = int(operands [0]) % int(operands[1])
  21.    print(operands[0] + "%" + operands[1] + "=" + str(result))

Explanation:

The solution code is written in Python 3.

Firstly prompt user to enter an equation using input function (Line 1).

Create if-else if statements to check if operator "+", "-", "*", "/" and "%" exist in the input equation. If "+" is found (Line 3), use split method to get the individual operands from the equation by using "+" as separator (Line 5). Output the equation as required by the question using string concatenation method (Line 6).  The similar process is repeated for the rest of else if blocks (Line 7 - 22).  

You might be interested in
? An attempt to harm damage or cause threat to a system or network is broadly termed as
Radda [10]

Answer:

A cyber attack or hacking

Explanation:

6 0
2 years ago
The quality of an image is compromised when, what are stretched ?​
german

Answer:

pixels

Explanation:

3 0
3 years ago
The use of logistics software at DCS (7 points)
Charra [1.4K]

Answer:18 th Century

Explanation:

3 0
2 years ago
How can I change my username here at brainly?
velikii [3]

Answer:

Explanation:

LOG OUT AND CHANGE IT

3 0
3 years ago
Read 2 more answers
Do all the countries have the same date format?
alexandr402 [8]
No they don’t have the same data format.
4 0
3 years ago
Other questions:
  • As a final lesson to her team, Katie shows them a job that has already been preflighted and is now getting ready to be sent to t
    7·1 answer
  • You are an inventor. You are taking out an ad in a newspaper because you want people to buy/use your product/invention. Include
    9·1 answer
  • Which best describes the relationship between maximum cost-per-click (max. cpc) bids and ad rank?
    12·1 answer
  • Caches are important to providing a high-performance memory hierarchy to processors. Below is a list of 32-bits memory address r
    9·1 answer
  • Communications that take the form of electronic junk mail or unsolicited e-mail are referred to as
    13·2 answers
  • identify three ways we use analog and digital signals in our everyday lives. Describe how radio telescopes are used to explore s
    7·2 answers
  • Que se puede observar en el escritorio de windows
    8·1 answer
  • Four example of computer software?​
    15·1 answer
  • What are the benefits of building redundancy into a network?
    12·1 answer
  • Explain impact of modern technology on human life​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!