write a program that displays the following menu:
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Score will be updated after checking for the following:
Input
1. data
Output
Geometry·Calculator
1.·Calculate·the·Area·of·a·Circle
2.·Calculate·the·Area·of·a·Rectangle
3.·Calculate·the·Area·of·a·Triangle
4.·Quit
Choice:·2
Enter·length:·5
Enter·width:·4
The·area·of·the·rectangle·with·length·5·and·width·4·is·20.
Geometry·Calculator
1.·Calculate·the·Area·of·a·Circle
2.·Calculate·the·Area·of·a·Rectangle
3.·Calculate·the·Area·of·a·Triangle
4.·Quit
Choice:·4
Bye!
menu = '''Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit'''
def circle():
r = int(input('Enter radius: '))
area = 3.1415*r*r
print(f"The area of the circle with radius {r} is {area:.2f}.")
def rectangle():
l = int(input('Enter length: '))
w = int(input('Enter width: '))
area = l*w
print(f"The area of the rectangle with length {l} and width {w} is {area}.")
def triangle():
s = int(input('Enter base: '))
h = int(input('Enter height: '))
area = s*h/2
print(f"The area of the rectangle with base {s} and height {h} is {area:.2f}.")
while True:
print(menu)
choice = input('Choice: ')
if choice == '4':
print('Bye!')
break
elif choice == '1':
circle()
elif choice == '2':
rectangle()
elif choice == '3':
triangle()
Comments
Leave a comment