import math
def square(x):
return math.pow(x, 2)
def square_root(x):
return math.sqrt(x)
def logarithm(x, base=math.e):
return math.log(x, base)
def trigonometry(angle, operation):
if operation == "sin":
return math.sin(math.radians(angle))
elif operation == "cos":
return math.cos(math.radians(angle))
elif operation == "tan":
return math.tan(math.radians(angle))
def calculator():
while True:
print("\nSimple Calculator")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Square")
print("6. Square Root")
print("7. Logarithm")
print("8. Sine")
print("9. Cosine")
print("10. Tangent")
print("11. Exit")
choice = int(input("Enter choice (1/2/3/4/5/6/7/8/9/10/11): "))
if choice not in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]:
print("Invalid choice. Please enter a number between 1 and 11.")
continue
if choice == 11:
break
num1 = float(input("Enter first number: "))
if choice == 5:
print("Square of", num1, "=", square(num1))
elif choice == 6:
print("Square root of", num1, "=", square_root(num1))
elif choice == 7:
base = float(input("Enter base (default is e): "))
print("Logarithm of", num1, "to the base", base, "=", logarithm(num1, base))
elif choice in [8, 9, 10]:
angle = float(input("Enter angle in degrees: "))
if choice == 8:
operation = "sin"
elif choice == 9:
operation = "cos"
elif choice == 10:
operation = "tan"
print(operation, "of", angle, "=", trigonometry(angle, operation))
else:
num2 = float(input("Enter second number: "))
if choice == 1:
print(num1, "+", num2, "=", add(num1, num2))
elif choice == 2:
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == 3:
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == 4:
print(num1, "/", num2, "=", divide(num1, num2))
calculator()