I have two programs I've been working on for my class but I keep getting different errors.
First one:
Write a boolean function called isTriangle that receives three numbers and returns true or false based on whether or not the
numbers are possible lengths of a triangle. If the sum of any two
sides is less than the third side, a triangle cannot be formed.
Here's what I have:
a = raw_input("Length of first side?")
b = raw_input("Length of second side?")
c = raw_input("Length of third side?")
import math
def isTriangle(a, b, c):
if a + b < c:
return 0
elif a + c < b:
return 0
elif b + c < a:
return 0
else:
return 1
print isTriangle
The closest I got, I would get a false even though the numbers formed a triangle.
Second program:
Write a function called heronsFomula that computes the area of a triangle given the length of the three sides. The formula is as
follows: sqrt(s(s-a)(s-b)(s-c)) ,where s is half the perimeter and a, b, and c are the lengths of the sides.
What I put in:
def sides (firstSide, secondSide, thirdSide):
def halfPerimiter(s):
s = (firstSide + secondSide + thirdSide)/2.0
print halfPerimiter
firstSide = raw_input ("Length of first side? ")
firstSide = float (firstSide)
secondSide = raw_input ("Length of second side? ")
secondSide = float (secondSide)
thirdSide = raw_input ("Length of third side? ")
thirdSide = float (thirdSide)
sides (firstSide, secondSide, thirdSide)
I haven't put the formula part in yet because I haven't successfully calculated s.
Thank you.