I was doing some practice problems in Bat coding and came across this ...
Given 3 int values, abc, return their sum. However, if one of the values is the same as another of the values, it does not count towards the sum. lone_sum(1, 2, 3) β 6 lone_sum(3, 2, 3) β 2 lone_sum(3, 3, 3) β 0
My solution was as follows.
def lone_sum(a, b, c): sum = a+b+c if a == b: if a == c: sum -= 3 * a else: sum -= 2 * a elif b == c: sum -= 2 * b elif a == c: sum -= 2 * a return sum
Is there a more pythonic way to do this?
source share