0
Can any one correct this code?
def mixx(num1,num2,num3): if num1 > num2 and num1 >num3 and num2 >num3 : print (list[num1 ,num2 ,num3 ]) elif num1 > num2 and num1 >num3 and num3 >num2 : print (list[num1 ,num3 ,num2 ]) elif num2 > num1 and num2>num3 and num1 >num3: print (list[num2 ,num1 ,num3 ]) elif num2 > num1 and num2 >num3 and num3 >num1 : print (list [num2 ,num3 ,num1 ]) elif num3 > num2 and num3>num1 and num2 >num1 : print (list [num3 ,num2 ,num1 ]) elif num3> num2 and num3>num1 and num1>num2 : print (list [num3 ,num1 ,num2 ]) else : print (num3 ) print (num2 ) print (num1 ) mixx (1,6,17)
4 Respostas
+ 3
What exactly are you trying to achieve with this code?
+ 2
Are u trying to arrange the list in ascending or descending order?
+ 1
You have some unnecessary conditions like in the first one num1>num2 and num2>num3 already mean that num1>num3 so that middle condition is logically redundant
0
You could do something like this in order to get the code to do the work for you
def mixx(a,b,c):
r = [a,b,c]
for i in range(1,3):
if r[i-1] < r[i]:
r[i-1],r[i] = r[i],r[i-1]
return r
n1 = 2
n2 = 7
n3 = 5
print(mixx(n1,n2,n3))