Exit while loop by user hitting ENTER key

前端 未结 14 1877
难免孤独
难免孤独 2020-12-08 23:01

I am a python newbie and have been asked to carry out some exercises using while and for loops. I have been asked to make a program loop until exit is requested by the user

14条回答
  •  情深已故
    2020-12-08 23:50

    If you want your user to press enter, then the raw_input() will return "", so compare the User with "":

    User = raw_input('Press enter to exit...')
    running = 1
    while running == 1:
        Run your program
    if User == "":
        break
    else
        running == 1
    

提交回复
热议问题