Answer:
Written in Python:
opcode = input("Enter operator: +,-,*,/")
operand1 = float(input("Operand 1: "))
operand2 = float(input("Operand 2: "))
if opcode == "+":
print(operand1 + operand2)
elif opcode == "-":
print(operand1 - operand2)
elif opcode == "*":
print(operand1 * operand2)
elif opcode == "/":
print(operand1 / operand2)
else:
print("Invalid Operator")
Step-by-step explanation:
This prompts user for operator
opcode = input("Enter operator: +,-,*,/")
The next two lines prompt user for two operands
operand1 = float(input("Operand 1: "))
operand2 = float(input("Operand 2: "))
This performs + operation if operator is +
if opcode == "+":
print(operand1 + operand2)
This performs - operation if operator is -
elif opcode == "-":
print(operand1 - operand2)
This performs * operation if operator is *
elif opcode == "*":
print(operand1 * operand2)
This performs / operation if operator is /
elif opcode == "/":
print(operand1 / operand2)
This displays invailid operator if input operator is not +,-,* or /
else:
print("Invalid Operator")