简体   繁体   English

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

[英]Python3 - Keep the program running after completing the script

Title basically says it all. 标题基本上说明了一切。 This is my script: 这是我的脚本:

    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)

How can i see the results after i typed a value of a and b without cmd automatically closing. 我键入a和b的值而cmd不自动关闭后,如何查看结果。

The simplest way would be to wait for user input 最简单的方法是等待用户输入

Add this at the end: 最后添加:

input("Press enter to close")

Alternatively, if you run the script from command line, the window won't disappear after the script ends. 另外,如果您从命令行运行脚本,则脚本结束后窗口不会消失。

Wait for another input 等待其他输入

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..")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM