Python Nested Conditions and Indentation

Curious about how nested conditions behave in Python? Take a look at this simple yet tricky snippet: marks = 78 passed = True At first glance, it seems straightforward—but the nested if-else structure requires careful consideration. Key takeaway: Understanding how indentation and conditional flow work in Python is crucial. The else here is tied to the inner if passed: condition—not the outer one. Always trace conditions step by step to avoid logical mistakes. What do you think the output is? Drop your answer below. #Python #CodingChallenge #Programming #Developer #LearnToCode #TechCareers

  • text

A , easy man , you did for fun but there is no point of wirting another if inside if condition and you assigned passed =True, anyway it is fun

A - Passed,Because marks is 78,which is >50,

Like
Reply
Joshua Higgins

Software Engineer | Computer Vision | Python | GCP | AgTech | N2

1d

passed should be the outcome, not a variable. and that failed result could be reached in the first line with a < operator. result will be passed, but since its already assigned true, theres no point entering this logic.

A Passed Nice fun to test !!

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories