Question
use python to complete the following: a. Open the starter code in the file: soda_can.py # A class to model soda cans # Implement a
use python to complete the following:
a. Open the starter code in the file: soda_can.py
# A class to model soda cans # Implement a class SodaCan with methods getSurfaceArea() and getVolume(). # The height and radius of a soda can object should be specified upon instantiation. import math class SodaCan(object): def __init__(self, height, radius): self.height = height self.radius = radius self.contents = None def getHeight(self): return self.height def getRadius(self): return self.radius def setHeight(self, height): self.height = height def setRadius(self, radius): self.radius = radius def getVolume(self): V = math.pi*(r**2)*h return 0 # fix this stub def getSurfaceArea(self): return 0 # fix this stub if __name__ == "__main__": # b. Construct a soda can with height h = 5 inches and radius r = 2.5 inches. # Then print out its volume V and surface area A. Use your methods getVolume and getSurfaceArea. can = SodaCan(5, 2.5) V = can.getVolume() S = can.getSurfaceArea() print("The volume of the can is V = %0.3f" % V) print("The surface area of the can is S = %0.3f" % S) # construct a second soda can with radius 2 inches and height 8 inches. # Which holds a greater volume? # Use an if statement to decide.
Complete the methods shown below to return the volume and surface area of the soda can. The following formulas should be familiar.
= ^2h
= 2 ^2 + 2h
Since the math module has been imported at the top, you can use math.pi any time you need to use .
def getVolume(self): return 0 # fix this stub
def getSurfaceArea(self):
return 0 # fix this stub
b. In the main section, construct a cylindrical soda can with radius 2.5 inches and height 5 inches. Then print out its volume V and surface area A. Use your methods getVolume and getSurfaceArea.
c. Now construct a second soda can with radius 2 inches and height 8 inches. Which holds a greater volume? Use an if statement to decide.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started