Python program to develop a simple calculator

#Python program to develop a simple calculator

def add(P, Q):
    return P +Q
def subtract(P, Q):
    return P - Q
def multiply(P, Q):
    return P * Q
def divide(P, Q):
    return P / Q

# Now we will take inputs from the user
print ("Please select the operation.”)
print (“a. Addition")
print (b. Subtraction")
print (c. Multiplication")
print (d. Division")

choice = input("Please enter choice (a/ b/ c/ d): ")

num1 = int (input ("Please enter first number: "))
num2 = int (input ("Please enter second number:"))

if choice == ‘a':
print (num1, “ + ", num2, “ = ", add(num1, num2))

elif choice == ‘c':
print (num, “ - ", num2, “ = ", subtract(num1, num2))

elif choice == ‘c':
print (num, “ * ", num2, “ = ", multiply(num1, num2))

elif choice == ‘c':
print (num, “ / ", num2, “ = ", divison(num1, num2))

else:
print ("This is an invalid input")

Output:
Please select the operation.
a. Addition
b. Subtraction
c. Multiplication
d. Division

Please enter choice (a/ b/ c/ d): b
Please enter the first number: 6
Please enter the second number: 4
6 - 4 = 2



Output:

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext