如何使用回车键退出程序

新手上路,请多包涵

Michael Dawson 在他的 Python Programming (第三版,第 14 页)一书中说,如果我输入 input("\n\nPress the enter key to exit.") 当用户按下 Enter 键时程序将结束。

我已经尝试过几次,但没有发生。我试过使用 Python 3.1 和 3.3。帮助将不胜感激。

原文由 user3306860 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
1 个回答

这是一个相当简单的概念,请看一下这个例子

x = input("Hit Enter to Exit, or Input any other key to continue ")

if not x :
    print("Exiting the Program.")
    exit()

else:
    a = int(input("\nEnter a Number : "))
    b = int(input("Enter another Number : "))
    print("Sum of the two numbers : ", a+b)

原文由 PreethiSamanthaBennet 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题