Write the code in a different way, in a more simplified form

Describe the TrianglePS(a, P, S) procedure that calculates on the side a of an equilateral triangle its perimeter P = 3·a and area S = a2**√3/4 (a – input, P and S — output parameters are all
parameters). Using this procedure, find the perimeters and areas of three equilateral triangles with these sides.How else can I write.Thank you in advance
“ `

import math
def proc(a):
P = 3 * a
S =a**2*sqrt*3/4
return [P, S]

x = [1, 2, 3]
for elem in x:


>Solution :

Bear in mind that a Python function can return a tuple – i.e., effectively more than one value. Therefore this could be greatly simplified as follows:

import random

def TrianglePS(a):
    return 3 * a, 3 ** 0.5 / 4 * a * a

for i in range(3):
    a = random.randrange(1, 10)
    p, s = TrianglePS(a)

Leave a Reply