python学习之 开关控制

开关自动切换学习

#python
state = lambda i: '已开启' if i else '已关闭'
TEST_KEY_WORD = ('开关一', '开关二', '开关三')
TEST_STATE = [1, 1, 1, ]

def run():
    content = input('请输入数字:')
    if '99' == content:
        for i in range(len(TEST_KEY_WORD)):
            print('[{}]{}({})\n'.format(i, TEST_KEY_WORD[i],state(TEST_STATE[i])))

    if '0' == content:
        TEST_STATE[0] =  not TEST_STATE[0]   #开关控制
        print('{}({})'.format(TEST_KEY_WORD[0],state(TEST_STATE[0])))

    if '1' == content:
        TEST_STATE[1] =  not TEST_STATE[1]   #开关控制
        print('{}({})'.format(TEST_KEY_WORD[1],state(TEST_STATE[1])))

    if '2' == content:
        TEST_STATE[2] =  not TEST_STATE[2]   #开关控制
        print('{}({})'.format(TEST_KEY_WORD[2],state(TEST_STATE[2])))

    return run()

你可能感兴趣的:(python学习之 开关控制)