## Help with right angled triangle function

This is the place for queries that don't fit in any of the other categories.

### Help with right angled triangle function

Hi guys, i'm currently learning with interactivepython: How to Think Like a Computer Scientist, and i'm stuck with an exercise on chapter Decisions and Selection.
1) Write a function is_rightangled which, given the length of three sides of a triangle, will determine whether the triangle is right-angled. Assume that the third argument to the function is always the longest side. It will return True if the triangle is right-angled, or False otherwise.
2) Extend the above program so that the sides can be given to the function in any order.
The 1st question is really easy and i could finish it but i can't do the 2nd question. Although there is answer to this, i still don't understand.
Code: Select all
`def is_rightangled(a,b,c):    is_rightangled = False    largest = a    if b > largest:        # largest = b        if abs((a**2) + (c**2) - (b**2)) < 0.001:            is_rightangled = True    if c > largest:        # largest = c        if abs((a**2) + (b**2) - (c**2)) < 0.001:            is_rightangled = True    else:        # largest = a        if abs((c**2) + (b**2) - (a**2)) < 0.001:            is_rightangled = True    return is_rightangled`

I wonder if there is any other simpler solution to this question and i hope for full explanation about the above answer. Thank you !
Last edited by Yoriz on Sat Nov 16, 2013 10:41 am, edited 2 times in total.
Reason: First post lock, Changed the title
guscer

Posts: 4
Joined: Sat Nov 16, 2013 10:03 am

### Re: Decisions and Selection excercise

Hi, welcome to the forum.
That question has been asked before on this forum, you can view it by the following link.
[ActiveCode] Help with right angled triangle function
Join the #python-forum IRC channel on irc.freenode.net!

Yoriz

Posts: 1325
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: Help with right angled triangle function

already seen it but i can't understand how the sorted function work.
guscer

Posts: 4
Joined: Sat Nov 16, 2013 10:03 am

### Re: Help with right angled triangle function

guscer wrote:already seen it but i can't understand how the sorted function work.

What about it can't you understand?
It takes an iterable(e.g. list, tuple, string...), and returns a sorted list of its items.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1461
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Help with right angled triangle function

guscer wrote:already seen it but i can't understand how the sorted function work.

Join the #python-forum IRC channel on irc.freenode.net!

Yoriz

Posts: 1325
Joined: Fri Feb 08, 2013 1:35 am
Location: UK