How to find largest among 3 numbers only using 2 if else in python

Question:

to find the largest number among the input three number using python the given constraint is some blank space, can anyone help me

the program:

A,B,C=[int(val) for val in input().split()]
print(______ if _______ else ________ if________ else ________)

i am new to python so i thought of using function but there no possibility to add the function so please help me to finish this code.

Asked By: Hatake Kakashi

||

Answers:

Since it is for your homework (as per comment above), I’m not giving you the "copy paste" solution, rather giving you some hint where you can start. Start with a pseudo code like below first, then try to have it in a single line

if A > B
    if C > A 
        # C is the largest
    else
       #
else
    if C > B
        # C is the largest
    else 
        # 
Answered By: Subhash Prajapati

A possible solution would be:

print(A if (A > B and A > C) else B if (B > A and B > C) else C)

However, keep in mind that python has a max function so without the constraints this would be much better:

print(max(A, B, C))
Answered By: annego
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.