crzcas

Calculator

Feb 6th, 2022
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #Python program to make basic calculator
  2.  
  3. def multiplication(num1, num2):
  4.     return num1 * num2
  5.  
  6. def addition(num1, num2):
  7.     return num1 + num2
  8.  
  9. def subtraction(num1, num2):
  10.     return num1 - num2
  11.  
  12. def divide(num1, num2):
  13.     return num1 / num2
  14.  
  15.  
  16. finished = False
  17. while finished == False:
  18.  
  19.     print("Hi, I am your personal calculator. I can help you with the following operations: ")
  20.  
  21.     print("Select a number:  1-Addition, 2-Subtraction, 3-Multiplication, 4-Division, 5-End")
  22.     operation = int(input("Choose  number of operation: 1/2/3/4/5 : "))
  23.  
  24.  
  25.     if operation == 5:
  26.         print()
  27.         print("Have a good day, bye.")
  28.         break
  29.  
  30.  
  31.     if (operation >= 1) and (operation <=5):
  32.         pass
  33.     else:
  34.         print()
  35.         print("The number of the operation must be between 1 and 5.")
  36.         break
  37.  
  38.  
  39.     value1 = int(input("Enter 1st number: "))
  40.     value2 = int(input("Enter 2nd number: "))
  41.  
  42.  
  43.     if operation == 1:
  44.         print(value1, "+", value2, "=", addition(value1, value2))
  45.         print()
  46.  
  47.     elif operation == 2:
  48.         print(value1, "-", value2, "=", subtraction(value1, value2))
  49.         print()
  50.  
  51.     elif operation == 3:
  52.         print(value1, "*", value2, "=", multiplication(value1, value2))
  53.         print()
  54.  
  55.     elif operation == 4:
  56.         print(value1, "/", value2, "=", divide(value1, value2))
  57.         print()
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment