Python3在完成脚本后保持程序运行

2024-09-24 22:31:55 发布

您现在位置:Python中文网/ 问答频道 /正文

标题基本上说明了一切。 这是我的剧本:

    keepProgramRunning = True
a = int(input("Type a value for a: "))
b = int(input("Type a value for b: "))
print("Result when multiplying: ", a*b)
print("Result when dividing: ", a/b)
print("...", a-b)
print("...", a+b)

在我键入a和b值而不使用cmd自动关闭后,如何才能看到结果。在


Tags: true标题forinput键入valuetyperesult
2条回答

等待另一个输入

keepProgramRunning = True
a = int(input("Type a value for a: "))
b = int(input("Type a value for b: "))
print("Result when multiplying: ", a*b)
print("Result when dividing: ", a/b)
print("...", a-b)
print("...", a+b)
input("Press [enter] to continue..")

最简单的方法是等待用户输入

在末尾添加:

input("Press enter to close")

或者,如果从命令行运行脚本,则在脚本结束后窗口不会消失。在

相关问题 更多 >