## 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
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

Posts: 1672
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: 1790
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.

Why ask for a solution when you have already seen it, dont you think you should of asked about what you didnt understand of the solution instead.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

Yoriz

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