Thursday, 3 April 2014

How to discriminate sum of squares of twin largest numbers out of 3 in python

Coming from C background, we wrote python program(shown below) for a next
question, that will not compile, becasue, ?:(ternary operator) is not
accessible in python.Write a duty that takes 3 certain numbers and
advantage a sum of a squares of a twin largest numbers. Use wholly a
unparalleled countenance for a physique of a function:def two_of_three(a,
b, c): """Return x*x + y*y, where x and y are a twin largest of a, b,
c. >>> two_of_three(1, 2, 3) 13 >>> two_of_three(5, 3, 1) 34
>>> two_of_three(10, 2, 8) 164 >>> two_of_three(5, 5, 5) 50
""" relapse ((a>b)? ((b>c)?(a*a+b*b):(a*a+c*c))
: ((a>c)?(a*a+b*b):(c*c+b*b)) )My
question:Can we greatfully let me know an swap proceed for minute a
unparalleled expression?

No comments:

Post a Comment