write a menu driven program to calculate area of circle and area of square and area of rectangle in python?
Answers
Language used:
Python Programming
Note:
Please do check the attachments given below to have a look at the process of evaluation and interpretation of code in IDLE.
Program:
def circle():
print("You choose Circle...")
radius=int(input("enter the radius : "))
print("Area of the circle with the radius of ",radius," units is", 3.14* (radius**2),"square units.")
def square():
print("You choose Square...")
side=int(input("enter the size of a side of a square : "))
print("Area of the square with the a side of ",side," units is",side**2,"square units.")
def rectangle():
print("You choose Rectangle...")
length=int(input("enter the length of the rectangle : "))
breadth=int(input("enter the breadth of the rectangle : "))
print("Area of the rectangle with length and breadth ",length, " ",breadth," units is",length*breadth,"square units.")
print("Menu-\n"
"1. Circle\n"
"2. Square\n"
"3. Rectangle\n")
x=int(input("Enter the corresponding number of a shape given in the menu, whose area you wants to calculate : "))
if x==1:
circle()
elif x==2:
square()
elif x==3:
rectangle()
else:
print("Wrong Input!")
Explanation:
We create a menu and take a number as an input that denotes the choice. Based on the choice, we make the corresponding shape's function call, that takes the needed inputs and prints the area.
Inputs:
Menu-
1. Circle
2. Square
3. Rectangle
For Circle:
Enter the corresponding number of a shape given in the menu, whose area you wants to calculate : 1
You choose Circle...
enter the radius : 5
For Square:
Enter the corresponding number of a shape given in the menu, whose area you wants to calculate : 2
You choose Square...
enter the size of a side of a square : 5
For Rectangle:
Enter the corresponding number of a shape given in the menu, whose area you wants to calculate : 3
You choose Rectangle...
enter the length of the rectangle : 2
enter the breadth of the rectangle : 3
For Wrong Input:
Enter the corresponding number of a shape given in the menu, whose area you wants to calculate : 9
Outputs:
For Circle:
Area of the circle with the radius of 5 units is 78.5 square units.
For Square:
Area of the square with the a side of 5 units is 25 square units.
For Rectangle:
Area of the rectangle with length and breadth 2 3 units is 6 square units.
For Wrong Input:
Wrong Input!
Cheers!!!!
Explanation:
I HOPE IT CAN HELP YOU DUDE