I guess what you're looking for is that when three values are entered, you get the maximum, the minimum, and the one that remains between the two. I guess you can not use list.sort
, sorted
, etc:
lado_1 = int(input("Ingrese lado:"))
lado_2 = int(input("Ingrese lado:"))
lado_3 = int(input("Ingrese lado:"))
min, med, max = sorted((lado_1, lado_2, lado_3))
print("Valor máximo: {}\nValor medio: {}\nValor mínimo: {}".format(max, med, min))
If you can only use conditionals, there are several algorithms but one very simple one is the following:
-
Starting we assign the three values to the variables minimo
, medio
and máximo
as they are entered.
-
We check if the minimum value is greater than the average, if so we exchange them.
-
We check if the average value is greater than the maximum, if we exchange them.
-
At this point we already have the maximum value. We only have to check again if the minimum value is greater than the average and if so we exchange them.
We have not really invented anything new, it's neither more nor less than the bubble sort ( bubble sort ) only simplified to the minimum expression. It would be simply:
lado_1 = int(input("Ingrese lado: "))
lado_2 = int(input("Ingrese lado: "))
lado_3 = int(input("Ingrese lado: "))
minimo, medio, maximo = lado_1, lado_2, lado_3
if minimo > medio:
minimo, medio = medio, minimo
if medio > maximo:
maximo, medio = medio, maximo
if minimo > medio:
minimo, medio = medio, minimo
print("\nValor máximo: {}\nValor medio: {}\nValor mínimo: {}".format(maximo,
medio,
minimo))
Enter side: 15
Enter side: -3
Enter side: 45
Maximum value: 45
Average value: 15
Minimum value: -3