This code calculates the volume and surface area of a cube with an edge length of edgeLength
. The user is prompted to input the edge length, which is then passed as an argument to two functions getVolume
and getSurface
.
getVolume
calculates the volume of the cube by raising the edge length to the power of 3 and returns the result.
getSurface
calculates the surface area of the cube by multiplying 6 by the square of the edge length and returns the result.
Finally, the returned values from the functions are printed with the strings “Volume: ” and “Surface: “. The repr
function is used to convert the integers to strings so they can be concatenated with the strings.
def getVolume(a):
volume = a * a * a
return volume
def getSurface(a):
surface = 6 * a * a
return surface
edgeLength = int(input("Please enter the edge length: "))
print("Volume: " + repr(getVolume(edgeLength)))
print("Surface: " + repr(getSurface(edgeLength)))
Please enter the edge length: 5
Volume: 125
Surface: 150