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.
perimeter = 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)
我被卡住了,需要尽快得到答案。如果有人能帮我,那就太好了。谢谢你!任何意见都很有帮助或想法。
你应该给出这样的参数:
print('the area of the triangle is: ' ,triangle_area(base, height))
print('the perimeter of the triangle is: ', triangle_perimeter(base, second, third))
改动:-
(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
代码:
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))
输出: -
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