gregmalcolm / python_koans

Python Koans - Learn Python through TDD
MIT License
4.94k stars 2.82k forks source link

about_triangle_project2.py #176

Closed KTatITAssist closed 6 years ago

KTatITAssist commented 6 years ago

Hi

I have added the code into triangle.py - and saved it!

def triangle(a, b, c):
    # DELETE 'PASS' AND WRITE THIS CODE
    #pass
    def triangle(a, b, c):
        if a <= 0 or b <= 0 or c <= 0:
            raise TriangleError(AttributeError('Negative edge is not allowed'))
        if a + b + c <= 2 * max(a, b, c):
            raise TriangleError(AttributeError('largest side should be smaller than sum of 2 other sides'))
        if a == b == c:
            return 'equilateral'
        elif a == b or b == c or c == a:
            return 'isosceles'
        return 'scalene'

# Error class used in part 2.  No need to change this code.
class TriangleError(Exception):
    pass

When I run the contemplate_koans.py I get the following error and I'm struggling to work out what is wrong.

I get "AssertionError: TriangleError not raised" on the line that calls triangle in about_triangle_project2.py the line is triangle(0, 0, 0)

Can you help me?

kjc commented 6 years ago

(I've fixed your code and text formatting. Let me know if I damaged anything.)

It looks like you've accidentally nested a new triangle function inside the given triangle function, instead of replacing it with your own.

KTatITAssist commented 6 years ago

Thank you. That was the problem. Sometimes one can't see the wood for the trees!

KTatITAssist commented 6 years ago

Thank you for your help. That was the problem!

Kathy Turner

KT@ITAssist Email: kt.itassist@gmail.com Mobile: 07926 702 047 Website: http://kt-itassist.co.uk

On 10 June 2018 at 23:59, Kevin J. Chase notifications@github.com wrote:

(I've fixed your code and text formatting. Let me know if I damaged anything.)

It looks like you've accidentally nested a new triangle function inside the given triangle function, instead of replacing it with your own.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gregmalcolm/python_koans/issues/176#issuecomment-396088707, or mute the thread https://github.com/notifications/unsubscribe-auth/AQwSTE7MO7h3VZjv-PSANjyI3xLzWDBzks5t7aS8gaJpZM4UhxqA .