asked 118k views
2 votes
Write a calculator program that will allow only addition, subtraction, multiplication & division. Have the

user enter two numbers, and choose the operation. Use if, elif statements to do the right operation based
on user input. using python

asked
User Sarbo
by
8.0k points

1 Answer

3 votes

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

operation = input("Which operation are you performing? (a/s/m/d) ")

if operation == "a":

print("{} + {} = {}".format(num1, num2, num1+num2))

elif operation == "s":

print("{} - {} = {}".format(num1, num2, num1-num2))

elif operation == "m":

print("{} * {} = {}".format(num1, num2, num1*num2))

elif operation == "d":

print("{} / {} = {}".format(num1, num2, num1/num2))

I hope this helps!

answered
User Gopika BG
by
7.8k points