def triangle_area(base, height):
\# This function should receive the base and height of a triangle as integers and return the area as a float.
area = base \* height // 2
return triangle_area
def triangle_perimeter(a,b,c):
\# This function should return the perimeter when 3 sides are provided.
perimet开发者_运维问答er = round(a+b+c)
return triangle_perimeter
def main():
base = int(input('Enter the base of the triangle: '))
Height = int(input('Enter the height of the triangle: '))
second = int(input('enter the second of the triangle: '))
third = int(input('Enter the third of the triangle: '))
print('the area of the triangle is: ' ,triangle_area)
print('the perimeter of the triangle is: ', triangle_perimeter)
I'm stuck and need answers quickly. if anyone can help me this would be great. Thank you. any input is very helpful or ideas.
You should give parameters like this:
print('the area of the triangle is: ' ,triangle_area(base, height))
print('the perimeter of the triangle is: ', triangle_perimeter(base, second, third))
Changes made:-
(1) change your return statement `triangle_area` to `area`
(2) change your return statement `triangle_perimeter` to `perimeter`
(3) Indentation correction
(4) Function calling in `print` statement
Code:-
def triangle_area(base, height):
#This function should receive the base and height of a triangle as integers and return the area as a float.
area = base*height // 2
return area
def triangle_perimeter(a,b,c):
#This function should return the perimeter when 3 sides are provided
perimeter = round(a+b+c)
return perimeter
base = int(input('Enter the base of the triangle: '))
height = int(input('Enter the height of the triangle: '))
second = int(input('enter the second side of the triangle: '))
third = int(input('Enter the third side of the triangle: '))
print('the area of the triangle is: ' ,triangle_area(base,height))
print('the perimeter of the triangle is: ', triangle_perimeter(base,second,third))
Output:-
Enter the base of the triangle: 8
Enter the height of the triangle: 12
enter the second side of the triangle: 4
Enter the third side of the triangle: 6
the area of the triangle is: 48
the perimeter of the triangle is: 18
精彩评论