流程控制.for语句

1.for循环可以遍历任何序列,可以通过索引迭代,也可以直接遍历,else语句会在循环正常执行完(注意不是break跳出而中断的)的情况下执行

# -*- coding: utf-8 -*-
"""
#
# Authors: limanman
# OsChina: http://my.oschina.net/pydevops/
# Purpose:
#
"""


def main():
    """Main function. """

    password = 'root_admin'
    # three times to input
    for i in xrange(3):
        # logout flag
        logout_flag = False

        login_pass = raw_input('please input login password: ').strip()
        if len(login_pass) == 0:
            continue
        # login in
        if password == login_pass:
            print 'welcome to login!'
            while True:
                user_choice = raw_input('''
                        1. run a command
                        2. send a file
                        3. exit this level
                        4. exit whole level
                        ''')
                if not user_choice.isdigit():
                    print 'Found Errors: input digit inside of other!'
                    continue
                user_choice = int(user_choice)
                if user_choice == 1:
                    print 'Found Notice: going to run a command!'
                elif user_choice == 2:
                    print 'Found Notice: going to send a file!'
                elif user_choice == 3:
                    print 'Found Notice: exit this level!'
                    break
                elif user_choice == 4:
                    print 'Found Notice: exit whole level!'
                    logout_flag = True
                    break
            # user logout flag to exit whole level!
            if logout_flag:
                break

if __name__ == '__main__':
    main()
    print

你可能感兴趣的:(流程控制.for语句)