Answer to Question #299827 in Python for Eren

Question #299827

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

  • The must be a main function that will display the menu and will ask for user's choice.
  • For each choice 1, 2 and 3, create an appropriate user-defined function for each task.
  • Provide validation for input.


Score will be updated after checking for the following:

  • 40 points deduction if there is no user defined function created at all.
  • 20 points deduction if all user defined function are void functions and no arguments.

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!







1
Expert's answer
2022-02-19T04:49:25-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS