Home > Back-end >  How to find largest among 3 numbers only using 2 if else in python
How to find largest among 3 numbers only using 2 if else in python

Time:02-04

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.

CodePudding user response:

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))

CodePudding user response:

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 
        # 
  • Related