161k views
0 votes
Lab: Create a Menu of Math Operations

• This lab is to be done in teams of two.
o
One person writes the main() function.
o
The 2nd person write the 5 functions and the .h files.
Combine the files into one project.
Test it, make corrections, test agains.
o Zip up and submit when you think it's finished.
Requirements
1. Create a Python program to perform various math functions.
2. The project will named Menu MathOperations. Spell it exactly as written.
3. Display a menu that lists the 5 operations that can be chosen + option 6 that
exits the program..
4. The 5 math operations are:
a. Area of a circle.
b. Volume of a cone.
c. Calculate Distance / vector / magnitude.
d. Pythagorean Theorem
e. Quadratic Formula.
5. After a math function is completed, the user can choose another math
operation.
6. Display numbers, in front of the menu choices to make it easier for the user to
choose a math operation.
7. Check the users input to see if its valid.
8. After user chooses a valid option, ask the user to input that the specific math
operation needs.
9. Call the math function and pass the data.
10.Receive a result back from the function that was called.
11.The main() will print out the results.
12.The main() and the five math functions will be in the same python file.
13.The quadFormula () function will return 3 values. Python can return 3 values.

1 Answer

1 vote

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:

User Sony Santos
by
8.8k points

No related questions found