If you want to build a online Engineering Calculator and want to write a python/program for this then you are in the right site. Here you can use this program i am providing you without a single error and perfect calculator :
# Function to add two numbers
def add(x, y):
return x + y
# Function to subtract two numbers
def subtract(x, y):
return x - y
# Function to multiply two numbers
def multiply(x, y):
return x * y
# Function to divide two numbers
def divide(x, y):
if y == 0:
return "Cannot divide by zero"
else:
return x / y
# Function to calculate the area of a circle
def circle_area(radius):
return 3.14159 * radius ** 2
# Function to calculate the area of a rectangle
def rectangle_area(length, width):
return length * width
# Function to calculate the area of a triangle
def triangle_area(base, height):
return 0.5 * base * height
# Main program loop
while True:
# Display menu options
print("Calculator Menu:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Circle Area")
print("6. Rectangle Area")
print("7. Triangle Area")
print("0. Exit")
# Get user choice
choice = int(input("Enter your choice: "))
# Perform the selected operation
if choice == 0:
print("Goodbye!")
break
elif choice == 1:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Result: ", add(num1, num2))
elif choice == 2:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Result: ", subtract(num1, num2))
elif choice == 3:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Result: ", multiply(num1, num2))
elif choice == 4:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Result: ", divide(num1, num2))
elif choice == 5:
radius = float(input("Enter the radius of the circle: "))
print("Result: ", circle_area(radius))
elif choice == 6:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
print("Result: ", rectangle_area(length, width))
elif choice == 7:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
print("Result: ", triangle_area(base, height))
else:
print("Invalid choice. Please try again.")