In: Computer Science
Write a program in python language, which accepts 2
numbers and a + sign (for addition) A sign - (for subtraction) A
sign * (for multiplication), / (for division) Then calculate and to
display the result of the operation he chose with the two numbers.
Displaying the appropriate message
Code Screenshot :
Executable Code:
#Prompting the user for input
op = input("Enter an Operation :")
x = int(input('Number 1: '))
y = int(input('Number 2: '))
#comparing and calculating the result
if op == '+':
print('{} + {} = '.format(x, y))
print(x + y)
elif op == '-':
print('{} - {} = '.format(x, y))
print(x - y)
elif op == '*':
print('{} * {} = '.format(x, y))
print(x * y)
elif op == '/':
print('{} / {} = '.format(x, y))
print(x / y)
else:
print('Invalid Operator')
Sample Output :