Advertisement
maki_

simple calculator that I need backed up

Nov 7th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #get users input
  2. op = input("Operation: ")
  3. num1 = float(input("First Number:"))
  4. num2 = float(input("Second Number:"))
  5.  
  6. #define the 5 operation functions
  7. def addition(a, b):
  8. print(float(num1 + num2))
  9.  
  10. def subtract(a, b):
  11. print(float(num1 - num2))
  12.  
  13. def multiply(a, b):
  14. print(float(num1 * num2))
  15.  
  16. def divide(a, b):
  17. print(float(num1 / num2))
  18.  
  19. def exponent(a, b):
  20. print(float(num1 ** num2))
  21.  
  22. #according to what user input, the operations are printed out accordingly
  23. if op == '+':
  24. addition(num1, num2)
  25. if op == '-':
  26. subtract(num1, num2)
  27. if op == '*':
  28. multiply(num1, num2)
  29. if op == '/':
  30. divide(num1, num2)
  31. if op == '^':
  32. exponent(num1, num2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement