Home > Python >Python Exercise: Largest Number Obtained

# Largest Number Obtained

Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, ().

For example, a, b, and c are 1, 2 and 3:

1 * (2 + 3) = 5
1 * 2 * 3 = 6
1 + 2 * 3 = 7
(1 + 2) * 3 = 9
So the maximum value that you can obtain is 9.


a = 3 b = 2 c = 4 x = a + b + c y = a + b * c z = c * (a + b) n = b * (a + c) m = a * b + c d = a * (b + c) e = a * c + b l = [x, y, z, n, m, d, e] item = 0 for i in l: if i > item: item = i l.remove(i) l.append(i) print(l[-1]) 
def largestobtainablenumber(a, b, c): maximum = 0 listofpossiblestrings = [] string1 = "" string2 = "" op = ("+", "*") for o1 in op: for o2 in op: string1 = "(a" + o1 + "b)" + o2 + "c" listofpossiblestrings.append(string1) string2 = "a" + o1 + "(b" + o2 + "c)" listofpossiblestrings.append(string2) for i in listofpossiblestrings: if eval(i) > maximum: maximum = eval(i) print(maximum) largestobtainablenumber(134,245246,264)
def equation1(x, y, z): return x * (y + z) def equation2(x, y, z): return x * y * z def equation3(x, y, z): return x + y * z def equation4(x, y, z): return (x + y) * z def largestnum(x, y, z): print("The maximum value you can obtain is " + str(max(equation1(x, y, z), equation2(x, y, z), equation3(x, y, z), equation4(x, y, z)))) input = 3, 4, 5 #input goes here v1, v2, v3 = input largestnum(v1, v2, v3)