Use Statements Create Calculator Program Uses 1 Input Example Person Inputs 2 3 Program Pr Q37073461

With the use of if statements, create a Calculator program thatonly uses 1 input.

For example, if a person inputs 2 + 3, the program should print5.

If the person inputs 3 – 1, the program should return 2.

If the person input 4 / 2, the program should return 2.

If the person inputs 3 * 2, the program should return 6.

Python


Solution


expression = input(“Enter a simple expression: “)n1 = float(expression.split()[0].strip())n2 = float(expression.split()[2].strip())ch = expression.split()[1].strip()print(expression + ” = “, end=”)if ch == ‘+’: print(n1 + n2)elif ch == ‘-‘: print(n1 – n2)elif ch == ‘*’:

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.