Create new modules for triangles, spheres, and cylinders and populate them with functions for calculating perimeter and area in the 2-D case (triangles) and volume and surface area in the 3-D cases (spheres and cylinders). Now modify the geometry.py file to work with these as options for the user.
Create new modules for triangles, spheres, and cylinders and populate them with functions for calculating perimeter and area in the 2-D case (triangles) and volume and surface area in the 3-D cases (spheres and cylinders). Now modify the geometry.py file to work with these as options for the user.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Recall the geometry example from class. Create new modules for triangles, spheres, and cylinders and populate them with functions for calculating perimeter and area in the 2-D case (triangles) and volume and surface area in the 3-D cases (spheres and cylinders). Now modify the geometry.py file to work with these as options for the user.
SUBMIT:
- A modified geometry.py file that works with the new modules you have created.
- triangle.py, sphere.py, and cylinder.py files which contain the methods specified above.
Attached: original geometry.py and an example for sphere.py

Transcribed Image Text:# The circle module has functions that perform
# calculations related to circles.
import math
pi=math.pi
# The area function accepts a circle's radius as an
# argument and returns the area of the circle.
def area(radius):
return math.pi * radius**2
# The circumference function accepts a circle's
# radius and returns the circle's circumference.
def circumference(radius):
return 2 * math.pi * radius

Transcribed Image Text:# This program allows the user to choose various
# geometry calculations from a menu. This program
# imports the circle and rectangle modules.
import circle
import rectangle
# The main function.
def main():
# The choice variable controls the loop
# and holds the user's menu choice.
choice = 0
while not(choice == 5):
# display the menu.
display_menu ( )
# Get the user's choice.
choice = int(input('Enter your choice: '))
# Perform the selected action.
if choice == 1:
r = float(input("Enter the circle's
radius: "))
print('The area is
{:.3f}.'.format(circle.area(r)))
elif choice == 2:
radius = float(input("Enter the
circle's radius: "))
print('The circumference is {:.3f}'.\
format(circle.circumference(radius)))
elif choice == 3:
width = float(input("Enter the
rectangle's width: "))
length = float(input("Enter the
rectangle's length: "))
print('The area is
{:.3f}'.format(rectangle.area(width, length)))
elif choice == 4:
width = float(input("Enter the
rectangle's width: "))
length = float(input("Enter the
rectangle's length: "))
print ('The perimeter is {:.3f}'.\
format(rectangle.perimeter(width, length)))
elif choice == 5:
print("Exiting the program...")
else:
print ("Error: invalid selection.")
# The display_menu function displays a menu.
def display_menu():
print(
print("1) Area of a circle")
print ("2) Circumference of a circle")
print ("3) Area of a rectangle")
print ("4) Perimeter of a rectangle")
print("5) Quit")
MENU for ")
# Call the main function.
main()
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education