❮ Previous Next ❯

Python Simple Calculator Program by using function


def add(x, y):

   return x + y

def subtract(x, y):

   return x - y



def multiply(x, y):

   return x * y

def divide(x, y):

   return x / y


print("Select operation.")

print("1:Add")

print("2:Subtract")

print("3:Multiply")

print("4:Divide")


choice = input("Enter choice(1/2/3/4):")


n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))


if choice == '1':
   print(n1,"+",n2,"=", add(n1,n2))


elif choice == '2':
   print(n1,"-",n2,"=", subtract(n1,n2))


elif choice == '3':
   print(n1,"*",n2,"=", multiply(n1,n2))


elif choice == '4':
   print(n1,"/",n2,"=", divide(n1,n2))

else:

print("Invalid input")

python problem
❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved