[Tutor] Finding biggest of three numbers

Flynn, Stephen (Life & Pensions) Steve.Flynn at capita.com
Wed Oct 7 04:16:25 EDT 2020


I probably doesn't make any difference.

If you had the comparisons in a hot loop and you had performance constraints then you could look as the IL for the code and compare and contrast that instructions used by the interpreter but my guess is that it'll probably result in the same instruction sequence.

Use whichever version you prefer - they are functionally equivalent.

S.

-----Original Message-----
From: Tutor <tutor-bounces+steve.flynn=capita.co.uk at python.org> On Behalf Of Manprit Singh
Sent: 07 October 2020 04:04
To: tutor at python.org
Subject: [Tutor] Finding biggest of three numbers

**EXTERNAL**

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
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


This message has been scanned by Capita systems, but if you believe it to be spam, please send it to spam at forcepoint.com.

Messages sent to spam at forcepoint.com are queued for email analysis by Forcepoint Threat Lab.
This email originates from outside of Capita.
Keep this in mind before responding, opening attachments or clicking any links. Unless you recognise the sender and know the content is safe.
If in any doubt, the grammar and spelling are poor, or the name doesn't match the email address then please contact the sender via an alternate known method.



This email is security checked and subject to the disclaimer on web-page: https://www.capita.com/email-disclaimer.aspx


More information about the Tutor mailing list