Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- try:
- num1 = float(input("Enter first number (Choose operator after): "))
- op = input("Enter operator: ")
- num2 = float(input("Enter second number: "))
- if op == "+":
- print("\nYour answer is " + (str(num1 + num2)))
- elif op == "-":
- prxint("\nYour answer is " + (str(num1 - num2)))
- elif op == "/":
- print("\nYour answer is " + (str(num1 / num2)))
- elif op == "*":
- print("\nYour answer is " + (str(num1 * num2)))
- elif op == "sqrt":
- print("\nThe root of " + str(num1) + " is " + (str(math.sqrt(num1))))
- elif op == "**":
- def raise_to_power(num1, num2):
- result = 1
- for i in range(num2):
- result = result * num1
- return result
- print("\n" + str(raise_to_power(int(num1), int(num2))))
- elif op == "fact":
- print(math.factorial(num1))
- except ValueError as err:
- print(err)
Advertisement
Add Comment
Please, Sign In to add comment