Python - Nesting Code Three Levels Deep

Description

Nesting Code Three Levels Deep

Demo

while True: 
   reply = input('Enter text:') 
   if reply == 'stop': 
       break # w w  w.  j  a va  2s. c  o 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