Answer:
import math
def main():
while True:
print("Menu MathOperations")
print("1. Area of a circle")
print("2. Volume of a cone")
print("3. Calculate Distance / vector / magnitude")
print("4. Pythagorean Theorem")
print("5. Quadratic Formula")
print("6. Exit")
choice = input("Enter your choice (1-6): ")
if choice == "1":
radius = input("Enter the radius of the circle: ")
area = circleArea(float(radius))
print("The area of the circle is", area)
elif choice == "2":
radius = input("Enter the radius of the cone: ")
height = input("Enter the height of the cone: ")
volume = coneVolume(float(radius), float(height))
print("The volume of the cone is", volume)
elif choice == "3":
x1 = input("Enter the x coordinate of point 1: ")
y1 = input("Enter the y coordinate of point 1: ")
x2 = input("Enter the x coordinate of point 2: ")
y2 = input("Enter the y coordinate of point 2: ")
distance = distanceBetweenPoints(float(x1), float(y1), float(x2), float(y2))
print("The distance between the points is", distance)
elif choice == "4":
side1 = input("Enter the length of side 1: ")
side2 = input("Enter the length of side 2: ")
hypotenuse = pythagoreanTheorem(float(side1), float(side2))
print("The length of the hypotenuse is", hypotenuse)
elif choice == "5":
a = input("Enter the coefficient of x^2: ")
b = input("Enter the coefficient of x: ")
c = input("Enter the constant: ")
root1, root2 = quadraticFormula(float(a), float(b), float(c))
print("The roots are", root1, "and", root2)
elif choice == "6":
print("Exiting...")
break
else:
print("Invalid choice. Please enter a number between 1 and 6.")
def circleArea(radius):
return math.pi * radius**2
def coneVolume(radius, height):
return math.pi * radius**2 * height / 3
def distanceBetweenPoints(x1, y1, x2, y2):
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
def pythagoreanTheorem(side1, side2):
return math.sqrt(side1**2 + side2**2)
def quadraticFormula(a, b, c):
discriminant = b**2 - 4*a*c
if discriminant < 0:
return None, None
else:
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
return root1, root2
if __name__ == "__main__":
main()
Step-by-step explanation: