File tree Expand file tree Collapse file tree 1 file changed +16
-13
lines changed
Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Original file line number Diff line number Diff line change 1- # Python Program to find the area of triangle
2- # calculates area of traingle in efficient way!!
3- a = 5
4- b = 6
5- c = 7
1+ def get_valid_side (prompt :str ):
2+ while True :
3+ try :
4+ value = float (input (prompt ))
5+ if value <= 0 :
6+ print ("Side must be positive" )
7+ continue
8+ return value
9+ except ValueError :
10+ print ("Invalid Input" )
611
7- # Uncomment below to take inputs from the user
8- # a = float(input('Enter first side: '))
9- # b = float(input('Enter second side: '))
10- # c = float(input('Enter third side: '))
1112
12- # calculate the semi-perimeter
13- s = (a + b + c ) / 2
13+ a = get_valid_side ("Enter side 1: " )
14+ b = get_valid_side ("Enter side 2: " )
15+ c = get_valid_side ("Enter side 3: " )
1416
15- # calculate the area
16- area = (s * (s - a ) * (s - b ) * (s - c )) ** 0.5
17+ semi_perimeter = (a + b + c ) / 2
18+
19+ area = sqrt ((s * (s - a ) * (s - b ) * (s - c )))
1720print ("The area of the triangle is %0.2f" % area )
You can’t perform that action at this time.
0 commit comments