⊗pyPmCdNIf 141 of 208 menu

Nested if statements in Python

The if else constructions can be nested in any way. However, in this case, it is necessary to observe the indents.

Let us have a variable tst:

tst = 3

Let's compare our variable with zero. In the first if we set the condition if the variable is less than or equal to 0. Inside this if we write another condition - if the number is less than or equal to 0. We also specify the else block for it. At the end of the first if else construction we write a message in case the number is less than 0:

if tst >= 0: if tst <= 5: print('less then or equal 5') else: print('more then 5') else: print('less then 0')

Let the variable month store the ordinal number of the month. It must be in the range from 1 to 12. Otherwise, let an error message be displayed. Next, for each correct month number, write a message about what season it belongs to.

Let the variable num store a number. If this number falls within the range from 10 to 99, then find the sum of the digits of this number. If the resulting sum is less than or equal to 9, then print a message that the sum of the digits is single-digit, otherwise print a message that the sum of the digits is two-digit.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline