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()
8 Answers
+ 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?
+ 1
Ok thanks.. got it
0
What result did you expect?
And what happened instead?
0
As per given condition it will print either yes or no.. but it prints nothing
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.
0
I am a new learner not beginner, of course I did.. you may try sir without input command..
0
Well, I just copied your code into Playground, ran it, gave input exactly as I explained above.
Output: 'No.'
0
What about "yes" criteria ?