I have three numbers M1, M2, M3 and range (a, b). I need 1) find the maximum number in the range or 2) print "Error", if at least one number is not in range (a, b). And 3) I need use the if-statement which was given by an instructor:
M1 = 101
M2 = 102
M3 = 103
a = 100
b = 1000
if a<M1<b:
if M2<=M1 and M3<=M1:
print(M1)
My first step was add analogical if-statements for the M2, M3. I have typed:
if a<M2<b:
if M1<=M2 and M3<=M2:
print(M2)
if a<M3<b:
if M1<=M3 and M2<=M3:
print(M3)
One can see that I don't code the second condition here. I have tried to union my three if-statement in one:
M1 = 99
M2 = 102
M3 = 103
a = 100
b = 1000
if a<M1<b:
if M2<=M1 and M3<=M1:
print(M1)
elif a<M2<b:
if M1<=M2 and M3<=M2:
print(M2)
elif a<M3<b:
if M1<=M3 and M2<=M3:
print(M3)
else:
print("Error")
but the console line is empty.
My second idea looks like for M1:
if a<M1<b:
if M2<=M1 and M3<=M1:
print(M1)
else:
print("Error")
And than add the same construction for M2, M3. But in the worst case I will see thee times Error, if all numbers are not in range.
Question. How to union three if-statements into one?