How can I define a variable in Python using if?

-1

What I basically want to do would be: Set from the inputs a max value and a minimum value but I do not know how to do it.

if lado1>lado2 and lado3:
...     print("A=lado1")
... 
 if lado2>lado1 and lado3:
...     print("A=lado2")
... 
if lado3>lado1 and lado2:
...     print("A=lado3")

How can I from the above if create that variable? Thank you very much!

    
asked by Ivan 04.04.2018 в 23:30
source

2 answers

0

The most appropriate thing would be after each if, to use: A = ladoQueQuieras and separate the ifs with else so that they do not all run unnecessarily. At the end, and outside the ifs, you use print(A) .

Something like:

if lado1>lado2 and lado1>lado3:
...     A=lado1
... 
elif lado2>lado1 and lado2>lado3:
...     A=lado2
... 
else
...     A=lado3
...
print(A)
    
answered by 05.04.2018 / 00:05
source
0

then basically you would have to make that entry first, which would be

  

side1 = int (input ())   side2 = int (input ())   side3 = int (input ())

And then as it says @FJSevilla then you would have to with the function max get the maximum and minimum with the function min then it would be like this:

  

Maximum = max (side1, side2, side3) Minimum = min (side1, side2, side3)

And python returns you the maximum and minimum.

It could also be a more extensive form that would be with conditionals evaluating all cases, then it would be:

If lado1>lado2 and lado2>lado3:
     Print('el máximo es', lado1,'y el mínimo es',lado3 )

elif lado1>lado3 and lado3>lado2:
     Print('el maximo es ',lado1,'el mínimo es ', lado3)

And so on ....

    
answered by 05.04.2018 в 00:06