Write a program in python to perform the following task according to users choice using menu:- 1. area of circle 2. area of rectangle 3. area of square 4. circumference of circle
Answers
from math import pi
r = float(input ("area of circle : "))
print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2))
# Python Program to find Area of a Rectangle
width = float(input('Please Enter the Width of a Rectangle: '))
height = float(input('Please Enter the Height of a Rectangle: '))
# calculate the area
Area = width * height
# calculate the Perimeter
Perimeter = 2 * (width + height)
print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)
int s=13;
int area_square=s*s;
printf("Area of the square=%d",area_square);Python Program - Calculate Circumference of Circle
print("Enter 'x' for exit.");
rad = input("Enter radius of circle: ");
if rad == 'x':
exit();
else:
radius = float(rad);
circumference = 2*3.14*radius;
print("\nCircumference of Circle =",circumference);
choice = "Yes"
while choice == "Yes":
print("1. Area of a Circle.")
print("2. Area of a Rectangle.")
print("3. Area of a Square.")
print("4. Circumference of a Circle.")
print()
shape = input("Enter the number of choice you'd like to proceed with: ")
print()
if shape == "1":
r = float(input("Enter the radius: "))
area = 3.14*r**2
print()
print(area, "is the area of the Circle.")
elif shape == "2":
l = float(input("Enter the length: "))
b = float(input("Enter the breadth: "))
area = l*b
print()
print(area, "is the area of the Rectangle.")
elif shape == "3":
s = float(input("Enter the length of a side: "))
area = s**2
print()
print(area, "is the area of the Square.")
elif shape == "4":
r = float(input("Enter the radius: "))
ccm = 2*3.14*r
print()
print(ccm, "is the circumference of the Circle.")
print()
choice = input("Would you like to go again? [Yes/No]: ")
print()