按下转义键时使Python 3.X程序退出

时间:2015-12-13 04:45:25

标签: python python-3.x

我只是乱搞一个简单的程序,如:

    import random
    game = True
    body = ['right foot', 'left foot', 'right hand', 'left hand']
    color = ['red', 'blue', 'green', 'yellow']
    while game:
        userinput = input('What would you like to do?')
        if userinput == '':
            random1 = random.choice(body)
            random2 = random.choice(color)
        print(random1 + ' ' + random2)
    if userinput == 'quit':
        game = False

我想知道,不是让用户输入quit,我怎么能让按下转义键时程序退出?

0 个答案:

没有答案