Sleddersquid

Calculator

Jun 27th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1.  
  2. import math
  3.  
  4. try:
  5.     num1 = float(input("Enter first number (Choose operator after): "))
  6.     op = input("Enter operator: ")
  7.     num2 = float(input("Enter second number: "))
  8.  
  9.     if op == "+":
  10.         print("\nYour answer is " + (str(num1 + num2)))
  11.  
  12.     elif op == "-":
  13.         prxint("\nYour answer is " + (str(num1 - num2)))
  14.  
  15.     elif op == "/":
  16.         print("\nYour answer is " + (str(num1 / num2)))
  17.  
  18.     elif op == "*":
  19.         print("\nYour answer is " + (str(num1 * num2)))
  20.  
  21.     elif op == "sqrt":
  22.         print("\nThe root of " + str(num1) + " is " + (str(math.sqrt(num1))))
  23.  
  24.     elif op == "**":
  25.         def raise_to_power(num1, num2):
  26.             result = 1
  27.             for i in range(num2):
  28.                 result = result * num1
  29.             return result
  30.  
  31.         print("\n" + str(raise_to_power(int(num1), int(num2))))
  32.  
  33.     elif op == "fact":
  34.         print(math.factorial(num1))
  35.  
  36. except ValueError as err:
  37.     print(err)
Advertisement
Add Comment
Please, Sign In to add comment