lambda keyword usage in PYTHON programe

Programe is:

#
#       lambda option usage în PYTHON programe
#       only one parameter restriction limits the structures
#       geometry problems exemples
#        A_circle = area of the circle
#        L_cilcre = the length of the circle
#        A_ square = area of the square
#        P_square = square perimeter
#        R = radius of the circle
#        L = the side of the square of the triangle
#        H = height
#        P_triangle = the perimeter of the equilateral triangle
#        A_triangle = area of the equilateral triangle
#        V_cube = volume of the cube
#        A_cube = total cube area
#        A_sphere = area of the sphere
#        V_sphere = volume of the sphere
#        H_tetra  = height tetrahedron
#        A_tetra = total area of the tetrahedron
#        V_tetra = volume of the tetrahedron
#        P_hexa = perimeter of the hexagon inscribed in a circle
#        A_hexa = area of the hexagon inscribed in a circle
#        PI = 3.14
#
#
r = 10
l = 10
A_square  = lambda L: L * L
P_square   = lambda L: 4 * L
A_circle   = lambda R: 3.14 * R * R
L_circle   = lambda R: 2 * 3.14 * R
P_triangle = lambda L: 3 * L
A_triangle = lambda L: (L * L * 3**0.5/2)/2
V_cube     = lambda L: L * L * L
A_sphere   = lambda R: 4 * 3.14 * R * R
V_sphere   = lambda R: 4 * 3.14 /3 * R * R * R
H_tetra    = lambda L: (2/3)**0.5 * L
A_tetra    = lambda L: 4* (L * L * 3**0.5/2)/2
V_tetra    = lambda L: (L * L * L )/(6 * 2**0.5)
P_hexa     = lambda R: 6 * R
A_hexa     = lambda R: R * R * (3 * 3** 0.5 /2)
print('IF radius R = ', r, 'circle area is : %.2f' %A_circle(r))
print('IF radius R = ', r, 'circle long is : %.2f' %L_circle(r))
print('IF side L = ', l, 'square area is : ', A_square(l))
print('IF side L = ', l, 'square perimeter is : ', P_square(l))
print('IF side L = ', l, 'triangle perimeter is : ', P_triangle(l))
print('IF side L = ', l, 'triangle perimeter is : %.2f' %A_triangle(l))
print('IF side L = ', l, 'cube volume is : ', V_cube(l))
print('IF radius R = ', r, 'sphere area is : %.2f' %A_sphere(r))
print('IF radius R = ', r, 'sphere volume is : %.2f' %V_sphere(r))
print('IF side L = ', l, 'tetrahedron height is : %.2f' %H_tetra(l))
print('IF side L = ', l, 'tetrahedron area is : %.2f' %A_tetra(l))
print('IF side L = ', l, 'tetrahedron volume is : %.2f' %V_tetra(l))
print('IF radius r = ', r, 'hexagon perimeter is : %.2f' %P_hexa(r))
print('IF radius r = ', r, 'hexagon area is : %.2f' %A_hexa(r))
List_function = [A_square, P_square, A_circle, L_circle ]
for element in List_function:
    print('%.2f' %element(10))

Results are:

============= RESTART: /Users/ionivan/Documents/LambndaFunctions.py ============
IF radius R =  10 circle area is : 314.00
IF radius R =  10 circle long is : 62.80
IF side L =  10 square area is :  100
IF side L =  10 square perimeter is :  40
IF side L =  10 triangle perimeter is :  30
IF side L =  10 triangle perimeter is : 43.30
IF side L =  10 cube volume is :  1000
IF radius R =  10 sphere area is : 1256.00
IF radius R =  10 sphere volume is : 4186.67
IF side L =  10 tetrahedron height is : 8.16
IF side L =  10 tetrahedron area is : 173.21
IF side L =  10 tetrahedron volume is : 117.85
IF radius r =  10 hexagon perimeter is : 60.00
IF radius r =  10 hexagon area is : 259.81
100.00
40.00
314.00
62.80


(March 29, 2022) 

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers