[Tutor] Fwd: Question regarding use of assignment expression in python 3.8.3
Manprit Singh
manpritsinghece at gmail.com
Sun Jun 7 01:48:41 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 :
area =sqrt( s * (s-a) * (s-b) * (s-c)) # sqrt means square root
where s = (a+b+c) / 2
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
---------- Forwarded message ---------
From: Manprit Singh <manpritsinghece at gmail.com>
Date: Sat, Jun 6, 2020 at 11:59 PM
Subject: Question regarding use of assignment expression in python 3.8.3
To: <tutor at python.org>
Dear all,
According to Heron's formula for finding area of a triangle , if the sides
of a triangle are a, b & c is :
area =sqrt( s * (s-a) * (s-b) * (s-c)) # sqrt means square root
where s = (a+b+c) / 2
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