Hey guys I am having problems with outputting the area and perimeter of a triangle given the sides using the Heron's formula. Here's my code:
def main():
a = int(input('Enter first side: '))
b = int(input('Enter second side: '))
c = int(input('Enter third side: '))
def area():
# calculate the sides
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
return area
area()
def perimeter():
# Calculate the perimeter
perim = a + b + c
return perim
perimeter()
print( 'Area is: ',format(area,'.1f'))
print( 'Perimeter is: ',format(perim,',.1f'))
main()
I am getting lots of errors like
- TypeError: non-empty format string passed to object.format
- NameError: name 'perim' is not defined
The way I'm supposed to do this is by asking for the sides in the main function and then calling the second one and then output the answers with one decimal place.
Can someone tell me what I doing wrong?