In: Computer Science
in python
Using this baseline template, write a program to input a choice from a menu
def calcArea(length, width):
pass
def CalcVolumeSa(length, width, height):
pass
def menu():
pass
def getValuesArea():
pass
def getValuesVolSa():
pass
def main():
menu()
if __name__ == "__main__":
main()
[1] - Calculate Area of rectangle
[2] - calculate Volume and Surface area of
Rectangle
[x} - Exit
Please select Option:
input the appropriate values and calculate and print out the results. For example:
Please select Option: 2
Please enter length: 4
Please enter width: 5
Please enter height: 6
For Rectangle of lenght 4.0, width 5.0 and height 6.0, the Volume
is 120.0, Surface Area is 148.0
Menu
[1] - Calculate Area of rectangle
[2] - calculate Volume and Surface area of Rectangle
[x} - Exit
Please select Option:
repeat the process until the user selects 'x'.
CODE:
def calcArea(length, width):
return length * width
def CalcVolumeSa(length, width, height):
return length * width * height, 2 * (length * width + width * height + height * length)
def menu():
while True:
print(
"[1] - Calculate Area of rectangle\n[2] - calculate Volume and Surface area of Rectangle\n[x] - "
"Exit\nPlease "
"select Option:", end="")
option = input()
if option == "1":
getValuesArea()
elif option == "2":
getValuesVolSa()
elif option == "x":
print("Exiting...")
break
def getValuesArea():
l = float(input("Please enter length:"))
b = float(input("Please enter width:"))
print("For Rectangle of length %.1f and width %.1f , the area is %.1f" % (
calcArea(l, b)))
def getValuesVolSa():
l = float(input("Please enter length:"))
b = float(input("Please enter width:"))
h = float(input("Please enter height:"))
vol, sa = CalcVolumeSa(l, b, h)
print("For Rectangle of length %.1f, width %.1f and height %.1f, the Volume is %.1f, Surface Area is %.1f" % (
l, b, h, vol, sa))
def main():
menu()
if __name__ == "__main__":
main()

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.