Python - Nesting Code Three Levels Deep

Description

Nesting Code Three Levels Deep

Demo

while True: 
   reply = input('Enter text:') 
   if reply == 'stop': 
       break # w ww  .j ava  2 s  .  co  m
   elif not reply.isdigit(): 
       print('Bad!' * 8) 
   else: 
       num = int(reply) 
       if num < 20: 
           print('low') 
       else: 
           print(num ** 2) 
print('Bye')

Result

Here, we add an if statement nested in the else clause of another if statement.

Related Topic