gpt4 book ai didi

python - 如何使用回车键退出程序

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:58 30 4
gpt4 key购买 nike

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

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

最佳答案

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

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)

关于python - 如何使用回车键退出程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21759946/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com