From 71ce9877b77785fa90ee0600c2d0ba0693ecbe84 Mon Sep 17 00:00:00 2001 From: Adityanagraj <42292430+Adityanagraj@users.noreply.github.com> Date: Mon, 18 May 2020 18:25:38 +0530 Subject: [PATCH 1/4] consists of area of various geometrical shapes In this program it consists of various area calculation of different geometrical shapes such as (square,rectangle) and many other shapes. --- maths/area.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 maths/area.py diff --git a/maths/area.py b/maths/area.py new file mode 100644 index 000000000000..0ecbaac5283a --- /dev/null +++ b/maths/area.py @@ -0,0 +1,68 @@ +""" +finding areas of various geomitrical shapes + +""" + +import math + + +def area_rectangle(base,height): + """ calculate the area of a rectangle + returns the base*height + >> area_rectangle(10,20) + 200 + """ + return base*height + +def area_square(side_length): + """ calculate the area of a square + returns the side*side + >>> area_square(10) + 100 + """ + return side_length*side_length + +def area_triangle(length,breadth): + """calculate the area of a triangle + returns the 1/2*length*breadth + >>> area_triangle(10,10) + 50 + """ + return 1/2*length*breadth + +def area_parallelogram(base,height): + """ calculate the area of a parallelogram + returns the base*height + >> area_parallelogram(10,20) + 200 + """ + return base*height + +def area_trapezium(base1,base2,height): + """ calculate the area of a trapezium + returns the 1/2(base1+base2)*height + >> area_trapezium(10,20,30) + 450 + """ + return 1/2*(base1+base2)*height + +def area_circle(radius): + """ calculate the area of a circle + returns the math.pi*(radius*radius) + >> area_circle(20) + 1256.6370614359173 + """ + return math.pi*(radius*radius) + + +def main(): + print('areas of all geometric shapes: \n') + print('Rectangle: ' + str(area_rectangle(10,20))) + print('Square: ' + str(area_square(10))) + print('Triangle: ' + str(area_triangle(10,10))) + print('Parallelogram: ' + str(area_parallelogram(10,20))) + print('Trapezium: ' + str(area_trapezium(10,20,30))) + print('Circle: ' + str(float(area_circle(20)))) + +if __name__ == "__main__": + main() From 8ce4759c5b0c84546d98957fea00b883f535dbbf Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 18 May 2020 22:52:11 +0200 Subject: [PATCH 2/4] print(f'Rectangle: {area_rectangle(10, 20)=}') --- maths/area.py | 98 +++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/maths/area.py b/maths/area.py index 0ecbaac5283a..35e26ac2872c 100644 --- a/maths/area.py +++ b/maths/area.py @@ -1,4 +1,4 @@ -""" +""" finding areas of various geomitrical shapes """ @@ -6,63 +6,75 @@ import math -def area_rectangle(base,height): - """ calculate the area of a rectangle - returns the base*height - >> area_rectangle(10,20) - 200 - """ - return base*height +def area_rectangle(base, height): + """ + Calculate the area of a rectangle + + >> area_rectangle(10,20) + 200 + """ + return base * height + def area_square(side_length): - """ calculate the area of a square - returns the side*side - >>> area_square(10) - 100 """ - return side_length*side_length + Calculate the area of a square + + >>> area_square(10) + 100 + """ + return side_length * side_length + + +def area_triangle(length, breadth): + """ + Calculate the area of a triangle -def area_triangle(length,breadth): - """calculate the area of a triangle - returns the 1/2*length*breadth - >>> area_triangle(10,10) - 50 + >>> area_triangle(10,10) + 50 """ - return 1/2*length*breadth + return 1 / 2 * length * breadth -def area_parallelogram(base,height): - """ calculate the area of a parallelogram - returns the base*height - >> area_parallelogram(10,20) - 200 + +def area_parallelogram(base, height): + """ + Calculate the area of a parallelogram + + >> area_parallelogram(10,20) + 200 + """ + return base * height + + +def area_trapezium(base1, base2, height): """ - return base*height + Calculate the area of a trapezium -def area_trapezium(base1,base2,height): - """ calculate the area of a trapezium - returns the 1/2(base1+base2)*height - >> area_trapezium(10,20,30) - 450 + >> area_trapezium(10,20,30) + 450 """ - return 1/2*(base1+base2)*height + return 1 / 2 * (base1 + base2) * height + def area_circle(radius): - """ calculate the area of a circle - returns the math.pi*(radius*radius) - >> area_circle(20) - 1256.6370614359173 """ - return math.pi*(radius*radius) + Calculate the area of a circle + + >> area_circle(20) + 1256.6370614359173 + """ + return math.pi * radius * radius def main(): - print('areas of all geometric shapes: \n') - print('Rectangle: ' + str(area_rectangle(10,20))) - print('Square: ' + str(area_square(10))) - print('Triangle: ' + str(area_triangle(10,10))) - print('Parallelogram: ' + str(area_parallelogram(10,20))) - print('Trapezium: ' + str(area_trapezium(10,20,30))) - print('Circle: ' + str(float(area_circle(20)))) + print("Areas of several geometric shapes: \n") + print(f"Rectangle: {area_rectangle(10, 20)=}") + print(f"Square: {area_square(10)=}") + print(f"Triangle: {area_triangle(10, 10)=}") + print(f"Parallelogram: {area_parallelogram(10, 20)=}") + print(f"Trapezium: {area_trapezium(10, 20, 30)=}") + print(f"Circle: {area_circle(20)=}") + if __name__ == "__main__": main() From 97642540fbb4ea40b5804ecc56714e51fc164bc3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 18 May 2020 23:02:43 +0200 Subject: [PATCH 3/4] Update area.py --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 35e26ac2872c..e3374f2250ef 100644 --- a/maths/area.py +++ b/maths/area.py @@ -31,7 +31,7 @@ def area_triangle(length, breadth): Calculate the area of a triangle >>> area_triangle(10,10) - 50 + 50.0 """ return 1 / 2 * length * breadth From c9c2bc866c15c764720c00947e9c75600252e617 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 18 May 2020 23:05:53 +0200 Subject: [PATCH 4/4] Areas of various geometric shapes: --- maths/area.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/maths/area.py b/maths/area.py index e3374f2250ef..0621bf5dd809 100644 --- a/maths/area.py +++ b/maths/area.py @@ -1,6 +1,5 @@ """ -finding areas of various geomitrical shapes - +Find the area of various geometric shapes """ import math @@ -67,7 +66,7 @@ def area_circle(radius): def main(): - print("Areas of several geometric shapes: \n") + print("Areas of various geometric shapes: \n") print(f"Rectangle: {area_rectangle(10, 20)=}") print(f"Square: {area_square(10)=}") print(f"Triangle: {area_triangle(10, 10)=}")