Lecture 5 (The Triangle Class Implementation)
Closed this issue · 2 comments
Hello,
In the first part of the triangle class implementation, when I run the below cell to check my code:
p1 = Point(0, 0)
p2 = Point(1, 0)
p3 = Point(0, 1)
t = Triangle(p1, p2, p3)
assert isclose(t.area(), 0.5), "Check your area calculation"
assert isclose(t.perimeter(), 1 + 1 + math.sqrt(2)), "Check your perimeter calculation"
assert isclose(t.edges()[0], 1)
assert isclose(t.edges()[1], math.sqrt(2))
assert isclose(t.edges()[2], 1)
assert isclose(t.angles()[0], math.pi / 4)
assert isclose(t.angles()[1], math.pi / 2)
assert isclose(t.angles()[2], math.pi / 4)
assert not t.contains_point(Point(1, 1))
I get the below error. Which is I believe is an error with the above code (which is already provided by the course) and not my actual code. Please suggest.
NameError Traceback (most recent call last)
Cell In[63], line 8
5 t = Triangle(p1, p2, p3)
7 assert isclose(t.area(), 0.5), "Check your area calculation"
----> 8 assert isclose(t.perimeter(), 1 + 1 + math.sqrt(2)), "Check your perimeter calculation"
9 assert isclose(t.edges()[0], 1)
10 assert isclose(t.edges()[1], math.sqrt(2))
NameError: name 'math' is not defined
Can you please explain what would this solve ?
Hi @esemsc-b7ff6690, thank you for raising this issue. The error you are getting is there because math
is not imported. Adding import math
above the assert statements should fix this problem.