Debugging 如何用一堆错误来限制代码,特别是这里的代码?I';我真的很困惑
所以我在上python实验课,我们刚刚开始讨论调试错误。我正在阅读实验室的资料,试图按照它告诉我的去做,但我不知道如何通过“狼篱笆”代码来发现错误,我只是总的来说感到困惑Debugging 如何用一堆错误来限制代码,特别是这里的代码?I';我真的很困惑,debugging,Debugging,所以我在上python实验课,我们刚刚开始讨论调试错误。我正在阅读实验室的资料,试图按照它告诉我的去做,但我不知道如何通过“狼篱笆”代码来发现错误,我只是总的来说感到困惑 import math 这里说,我需要使用errlog方法,并使用wolf fensing来识别错误,我不知道该怎么做,因为实验室讲师没有给我们任何可以处理的东西 ## @TODO - add the errlog method and use wolf fencing to identify the errors in t
import math
这里说,我需要使用errlog方法,并使用wolf fensing来识别错误,我不知道该怎么做,因为实验室讲师没有给我们任何可以处理的东西
## @TODO - add the errlog method and use wolf fencing to identify the errors in this code
def validate_triangle(sides):
return True
def get_angle(sides):
# Using the law of cosines
# c^2 = a^2 + b^2 - 2abcos(C)
# cos(C) = (a^2 + b^2 - c^2)/(2ab)
a = sides[0]
b = sides[1]
c = sides[2]
num = math.pow(a, 2) + math.pow(b, 2) + math.pow(c, 2)
den = 2*a*b
val = num/den
angle = math.acos(val)
return angle
def get_height(sides):
C = get_angle(sides) # angle formed by sides a and b, opposite side c
height = sides[0]*math.sin(C)
return height
def get_area(sides):
base = sides[1]
height = get_height(sides)
area = (1/2.)*base*height
return area
def get_area_heron(sides):
if (not validate_triangle(sides)):
return None
a = sides[0]
b = sides[1]
c = sides[2]
s = 0.5*(a + b + c)
area = math.sqrt(s*(s-a)*(s-b)*(s-c))
return area
print('name is',__name__)
if __name__ == "__main__":
sides = (3, 4, 5)
areaHeron = get_area_heron(sides) # This should be 6.0
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))
sides = (4, 5, 3)
areaHeron = get_area_heron(sides) # This should be 6.0 (same as 3,4,5)
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))
sides = (2, 2, 2*math.sqrt(2)) # equilateral right triangle
areaHeron = get_area_heron(sides) # This should be 2.0
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))
sides = (4, 4, 5) # This is an invalid triangle
areaHeron = get_area_heron(sides) #
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))
sides = (3, 4, 8) # This is an invalid triangle
areaHeron = get_area_heron(sides) # This should be None
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))
sides = (3, 4) # This is an invalid triangle
areaHeron = get_area_heron(sides) # This should be None
area = get_area(sides)
print('Area of triangle with sides={} is {} {}'.format(str(sides), str(area), str(areaHeron)))