Advertisement
Guest User

new

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. ''' Program make a simple calculator that can add, subtract, multiply and divide using functions '''
  2.  
  3. # This function adds two numbers
  4. def add(x, y):
  5.    return x + y
  6.  
  7. # This function subtracts two numbers
  8. def subtract(x, y):
  9.    return x - y
  10.  
  11. # This function multiplies two numbers
  12. def multiply(x, y):
  13.    return x * y
  14.  
  15. # This function divides two numbers
  16. def divide(x, y):
  17.    return x / y
  18.  
  19. print("Select operation.")
  20. print("1.Add")
  21. print("2.Subtract")
  22. print("3.Multiply")
  23. print("4.Divide")
  24.  
  25. # Take input from the user
  26. choice = input("Enter choice(1/2/3/4):")
  27.  
  28. num1 = int(input("Enter first number: "))
  29. num2 = int(input("Enter second number: "))
  30. if choice == '1':
  31.    print(num1,"+",num2,"=", add(num1,num2))
  32.    
  33. elif choice == '2':
  34.    print(num1,"-",num2,"=", subtract(num1,num2))
  35.  
  36. elif choice == '3':
  37.    print(num1,"*",num2,"=", multiply(num1,num2))
  38.  
  39. elif choice == '4':
  40.    print(num1,"/",num2,"=", divide(num1,num2))
  41. else:
  42.    print("Invalid input")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement