[Tutor] Finding biggest of three numbers

Manprit Singh manpritsinghece at gmail.com
Tue Oct 6 23:03:46 EDT 2020


Dear sir ,
consider the problem of finding the biggest of three numbers . The most
clean and clear solution  to this problem is using max( ) function. But my
question is about the basic program for this problem that is taught in
schools, to make the students learn about if statement, the program is
given below :

a = int(input("Input first number"))
b = int(input("Input second number"))
c = int(input("Input second number"))
if a > b and a > c:
    x = a
elif b > c:
    x = b
else:
    x = c
print("The greatest number is", x)

Now , i am going to make changes in the above written program :

a = int(input("Input first number"))
b = int(input("Input second number"))
c = int(input("Input second number"))
if b < a > c:
    x = a
elif b > c:
    x = b
else:
    x = c
print("The greatest number is", x)

Here in the second version, I have used chaining in the condition written
with if . So what are your views about this second version, which one must
be preferred ? - second or first version of the solution to the problem .

Just need to know in which circumstances I should prefer chaining, and in
which circumstances I should avoid it .

Regards
Manprit Singh


More information about the Tutor mailing list