[Tutor] Question regarding use of assignment expression in python 3.8.3

Manprit Singh manpritsinghece at gmail.com
Sat Jun 6 00:11:19 EDT 2020


Dear all,

According to Heron's formula for finding area of a triangle , if the sides
of a triangle  are a, b & c is :
s = (a+b+c) / 2
area =sqrt( s * (s-a) * (s-b) * (s-c))   // sqrt means square root

so for finding the area of the triangle using Heron's formula in Python ,
if i write code like this , will it be a valid practise ?
I have used assignment expression while calculating the  area

a = int(input("Enter value of first side"))                     // Assuming
value is integer
b = int(input("Enter value of second side"))               // Assuming
value is integer
c = int(input("Enter value of third side"))                   // Assuming
value is integer
area = ((s := (a+b+c) /2) *(s -a)*(s-b)*(s-c))**0.5
print("Area of the triangle is", area)

Regards
Manprit Singh


More information about the Tutor mailing list