RagingAcid

Calculator

Mar 7th, 2019
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. y = 0
  2. x = 0
  3. z = 0
  4. def add(x,y):
  5.     z = x+y
  6.     return z
  7.  
  8. def subtract(x,y):
  9.     z = x-y
  10.     return z
  11.  
  12. def multiply(x,y):
  13.     z = x*y
  14.     return z
  15.  
  16. def divide(x,y):
  17.     z = x/y
  18.     return z
  19.  
  20. def power(x,y):
  21.     z = x**y
  22.     return z
  23.  
  24. def root(x):
  25.     z = x**0.5
  26.     return z
  27.    
  28. x = input("First number of operation")
  29. x = float(x)
  30.  
  31. operations = input("What operation would you like to use? Your choices are: Add, Subtract, Multiply, Divide, Power, Root")
  32. operations = operations.lower()
  33. if operations == "root":
  34.     ans = root(x)
  35. else:
  36.     y = input("What is the second number of the operation?")
  37. y = float(y)
  38. if operations == "add":
  39.     ans = add(x,y)
  40. if operations == "subtract":
  41.     ans = subtract(x,y)
  42. if operations == "multiply":
  43.     ans = multiply(x,y)
  44. if operations == "divide":
  45.     ans = divide(x,y)
  46. if operations == "power":
  47.     ans =power(x,y)
  48.    
  49. print(ans)
Add Comment
Please, Sign In to add comment