Nested if demo : For « Language Basics « Python






Nested if demo

Nested if demo

name = raw_input('What is your name? ')

if name.endswith('Yin'):
    if name.startswith('Mr.'):
        print 'Hello, Mr. Yin'
    elif name.startswith('Mrs.'):
        print 'Hello, Mrs. Yin'
    else:
        print 'Hello, Yin'
else:
    print 'Hello, stranger'

           
       








Related examples in the same category

1.Dictionary for loopDictionary for loop
2.For loop demoFor loop demo
3.for with else for with else
4.Calculating compound interest.Calculating compound interest.