0

why nested if is not working ?

def is_triangle(): print("This condition check whether you can make a triangle with given \ 3 lengths or not") stick_1 = int(input("Enter stick 1 length: ")) stick_2 = int(input("Enter stick 2 length: ")) stick_3 = int(input("Enter stick 3 length: ")) if stick_1 + stick_2 == stick_3: if stick_2 + stick_3 == stick_1: if stick_3 + stick_1 == stick_2: print( "Yes") else: print("No") is_triangle()

25th Feb 2019, 11:08 AM
Aakash Gupta
Aakash Gupta - avatar
8 Respuestas
+ 1
Originally you wrote that you get no output at all. Now it's about getting the wrong output all of a sudden. Anyway, your nested loop works like this: first it is checked if s1 + s2 = s3. Only if the answer is yes, it is checked if s2 + s3 = s1. And only if this as well is the case, your code checks if s3 + s1 = s2. So all three conditions have to be true. Sure you wanted to do it like this?
25th Feb 2019, 1:59 PM
HonFu
HonFu - avatar
+ 1
Ok thanks.. got it
26th Feb 2019, 10:33 AM
Aakash Gupta
Aakash Gupta - avatar
0
What result did you expect? And what happened instead?
25th Feb 2019, 11:19 AM
HonFu
HonFu - avatar
0
As per given condition it will print either yes or no.. but it prints nothing
25th Feb 2019, 11:37 AM
Aakash Gupta
Aakash Gupta - avatar
0
Have you given the inputs? Here on Sololearn you need to do that before the code runs, in that popup window. In your case in 3 different lines.
25th Feb 2019, 11:43 AM
HonFu
HonFu - avatar
0
I am a new learner not beginner, of course I did.. you may try sir without input command..
25th Feb 2019, 11:56 AM
Aakash Gupta
Aakash Gupta - avatar
0
Well, I just copied your code into Playground, ran it, gave input exactly as I explained above. Output: 'No.'
25th Feb 2019, 1:42 PM
HonFu
HonFu - avatar
0
What about "yes" criteria ?
25th Feb 2019, 1:44 PM
Aakash Gupta
Aakash Gupta - avatar