# Python, how to declare a variable between a max and a min?

1

A question if I define a maximum and a minimum using If, how can I define the number or variable that is in the middle? Thank you very much!

``````Lado1=int(input("Ingrese lado:"))
...
...
...
>>> A
5

...
...
...
>>> B
3
``````

asked by Ivan 05.04.2018 в 22:49
source

2

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:"))

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: "))

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

source
0

You could try this code, it is an adaptation to a code made in c ++, it would help you only if you want to get the intermediate in case of only 3 numbers .

``````    Lado1=int(input("ingrese un numero\n"))

print("El numero intermedio es " + str(Lado1))
print("El numero intermedio es " + str(Lado2))
print("El numero intermedio es " + str(Lado3))
else
print("No existe número intermedio")
``````

``````>>> lado1 = 6