When might someone absolutely have to use a nested conditional? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

When might someone absolutely have to use a nested conditional?

Iā€™m reading Think Python and it is talking about nested conditionals and chained conditionals and in the text it says to avoid nested conditionals where you can and rewrite it with logical operators so that itā€™s less confusing. Which brings me to my questionā€¦ in what sort of situation is using nested conditionals unavoidable? Can anyone provide an example?

7th Jul 2021, 7:12 AM
Jocelyn
Jocelyn - avatar
2 Respostas
+ 5
if a: if b: print("a & b are true") else: print("a is true but b is false") else: if b: print("a is false but b is true") else: print("a & b are false") you may see by yourself when you cannot avoid nesting conditonal or simplify the conditional by using 'and' or 'or' in conditions...
7th Jul 2021, 7:59 AM
visph
visph - avatar
+ 1
Thank you both! I think I understand it now.
7th Jul 2021, 9:01 PM
Jocelyn
Jocelyn - avatar