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
tiny-mole [99]
3 years ago
12

Write a program that will read and evaluate a mathematical expression. The expression is of the form: oprand1 op operand2, where

operand1 and operand2 are positive integers and op is an operator, which is either +, -, * or /. For example: 24 + 65 and 276 * 2 are legal expressions. Assumption: There is a single space between each operand and the operator.
Computers and Technology
1 answer:
Vedmedyk [2.9K]3 years ago
7 0

Answer:

ques=(input("Enter question "))

br = ques.split()

operand1= int(br[0])

operand2= int(br[2])

op= br[1]

if (operand1 >0 and operand2 >0):

   if op == '+':

       print(operand1, "+", operand2, "=",operand1 + operand2)

   elif op == '-':

       print(operand1, "-", operand2, "=",operand1 - operand2)

   elif op == '*':

       print(operand1, "*", operand2, "=",operand1 * operand2)

   elif op == '/':

       print(operand1, "/", operand2, "",operand1 / operand2)

   else:

       print("Please enter  a correct operator")

else:

       print("Please ener a positive number")

Explanation:

ques=(input("Enter question "))

This line prompts for an input like 2 + 23

br = ques.split()

The split function takes the input and breaks it into different parts and places it in a list with each element having an index number starting from zero

operand1= int(br[0])

operand2= int(br[2])

op= br[1]

we use the index numbers to access their location and assign them to operand1 operand2 and op(which is the operator). here we assign operand1 and operand2 to an integer data type and leave op as a string.

if (operand1 >0 and operand2 >0):

The if statement here ensures that both operand1 and two are positive.

   if op == '+':

       print(operand1, "+", operand2, "=",operand1 + operand2)

   elif op == '-':

       print(operand1, "-", operand2, "=",operand1 - operand2)

   elif op == '*':

       print(operand1, "*", operand2, "=",operand1 * operand2)

   elif op == '/':

       print(operand1, "/", operand2, "",operand1 / operand2)

<em>checks the operators, carries out the calculation and prints the solution.</em>

   else:

       print("Please enter  a correct operator")

the else statements handles all possible errors that may occur when writing the operator

else:

       print("Please enter a positive number")

This prompts the user to enter a positive number

Another approach would be to create functions for each operator and call those functions whenever the operator is inputted.

You might be interested in
A computing company is running a set of processes every day. Each process has its own start time and finish time, during which i
Helga [31]

Answer:

Above all else, let us show that this issue has the greedy choice property.

This implies that worldwide ideal arrangement can be gotten by choosing local ideal arrangements. Presently notice the following:

The global optimal solution of the issue requests us to track down the minimum number of times process_check module should be run.

It is likewise referenced that during each running interaction, process_check module should be called atleast once. Along these lines, the minimum possible number of process_check calls happens when process_check is made close to the quantity of the processes that are run.

Along these lines, we see that the global optimal solution is shaped by choosing optimal answer for the nearby advances.

Along these lines, the issue shows greedy choice property. Thus, we can utilize a greedy algorithm for this issue.

The greedy step in this calculation is to postpone the process_check as far as might be feasible. Thus, it should be run towards the finish of each interaction. So the following algorithm can be utilized:

Sort the cycles by utilizing the completion times.

Towards the finish of the 1st process in the arranged list, run the process_check module. Right now any process that is now running is removed the arranged rundown. The main interaction is additionally removed from the sorted list.

Now repeat stage 2, till all processes are finished.

In the above mentioned algorithm, the costliest advance is the step of sorting. By utilizing the optimal sorting algorithm, for example, merge sort, we can achieve it in O(n log n) asymptotic time.

Along these lines, this greedy algorithm additionally takes O(n log n) asymptotic time complexity.

5 0
3 years ago
Ryder has discovered the power of creating and viewing multiple workbooks. ​ ​ Ryder wants to use a layout in which the workbook
777dan777 [17]

Answer:

Click the Cascade option button

Explanation:

Based on the description of what Ryder is attempting to accomplish, the next step that he needs to do would be to Click the Cascade option button. This option will cause all the windows of the currently running applications to overlap one another but at the same time show their title bars completely visible in order to let the user know their open status. Which is exactly what Ryder is attempting to make as his desired layout for the workbooks. Therefore this is the option he needs.

4 0
3 years ago
Which method(s) must a serializable class, implement?
Cloud [144]

Answer: None of the given option is correct

Explanation:

A serializable class is implemented, when an object is serializable interface. If you want to serialize one of your classes, then the class must implemented in the Serializable interface. To implement the serializable interface, convert a class into the series of bytes and when serializable object might reference your class. Serializable classes are useful when you wanted to persist cases of the class or send them over wire.

5 0
4 years ago
Out of a list of the values 2, 45, 18, 22, 8, and 37, what result would the MAX function return?
Vika [28.1K]
37 most likely.
No programming language is specified, and you didn't put what the function is, so assuming it's already implemented, MAX should display the highest number.
8 0
4 years ago
Read 2 more answers
What kind of table is a pasted Word table that can be edited with Word from within PowerPoint without changing the data in your
igomit [66]

D. Integrated

Or

A. Embedded

7 0
3 years ago
Read 2 more answers
Other questions:
  • During an experiment, if you purpose change the temperature to test a hypothesis the temperature is called what??
    6·1 answer
  • How might the website owner use theses details other than to verify login details?
    6·2 answers
  • Which of the following is a disadvantage of using face-to-face communication over other communication channels? A) There is lag
    13·1 answer
  • 11.The shortcut keys used to center a paragraph are&lt;br /&gt;a. CTRL+T&lt;br /&gt;b. CTRL+M&lt;br /&gt;c. CTRL+SHIFT+T d. CTRL
    7·1 answer
  • Do you think I could create a working animatronic like the one from five nights at freddys
    12·2 answers
  • Design a program that asks the user to enter a string containing a series of single digit numbers with nothing separating them.
    7·1 answer
  • The East Coast sales division of a company generates 62 percent of total sales. Based on that percentage, write a Python program
    7·1 answer
  • We have constructed a Player Class for you. Add the following: public static variable: int totalPlayers Static variable should b
    8·1 answer
  • Python code 100 Random Numbers (twice)
    9·1 answer
  • What would be an ideal scenario for using edge computing solutions?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!