In: Computer Science
Make a python calculator which deals with arithmetic include plus, minus, divide, and multiply as well as explaining each answer and use if statement using sign operator.
Implemented the code as per the requirement. As python is
indentation specific, you may not get the formatted text while
copying the code,
so I'm attaching the screenshots of the code for reference. Please
make sure when you are executing the below code you have same
format, especially tabs.
Please comment if any modification required or if you need any help.
code:
====
inp = input("Enter the expression: ") if(inp.__contains__("+")): left = int(inp.split("+")[0].strip()) right = int(inp.split("+")[1].strip()) print("Addition of ",left," and ",right," is",(left+right)) elif(inp.__contains__("-")): left = int(inp.split("-")[0].strip()) right = int(inp.split("-")[1].strip()) print("Subtraction of ",left," from ",right," is",(left-right)) elif(inp.__contains__("*")): left = int(inp.split("*")[0].strip()) right = int(inp.split("*")[1].strip()) print("Multiplication of ",left," and ",right," is",(left*right)) elif(inp.__contains__("/")): left = int(inp.split("/")[0].strip()) right = int(inp.split("/")[1].strip()) print("Division of ",left," and ",right," is",(left/right)) else: print("Invalid input!!!")
code screenshot:
=============
Output:
======