-
Notifications
You must be signed in to change notification settings - Fork 402
/
Areas.py
56 lines (43 loc) · 1.5 KB
/
Areas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Program to calculate the areas of 2d shapes
import math
def square(side):
area = side * side
return area
def rectangle(length, breadth):
area = length * breadth
return area
def triangle(side1, side2, side3):
s = (side1 + side2 + side3)/2
area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
return area
def circle(radius):
area = 3.14 * radius * radius
return area
final_area = 0.0
print("Choose the shape you want to calculate area of: ")
while True:
print("Square, Rectangle, Triangle, Circle")
shape = input('>> ')
print(shape.lower())
if shape.lower() == "square":
side = float(input("Enter the value of side: "))
final_area = square(side)
break
elif shape.lower() == "rectangle":
length = float(input("Enter value of length: "))
breadth = float(input("Enter value of breadth: "))
final_area = rectangle(length, breadth)
break
elif shape.lower() == "triangle":
side1 = float(input("Enter the value of 1st side: "))
side2 = float(input("Enter the value of 2nd side: "))
side3 = float(input("Enter the value of 3rd side: "))
final_area = triangle(side1, side2, side3)
break
elif shape.lower() == "circle":
radius = float(input("Enter the value of radius: "))
final_area = circle(radius)
break
else:
print("Please choose a shape from the given 4 or check your spelling again")
print(f"The area of the shape is: {final_area}")