Python程序将运行,但不会保持打开状态让我查看输出

时间:2017-12-30 21:00:55

标签: python python-3.x output

我是Python的新手,我刚开始自己​​的程序。

我有一些使用IDLE创建的程序。这些程序将运行,但输出在屏幕上大约1/4秒才会消失......

我在互联网上搜索过但我还没有找到解决方案......有人可以解释为什么会这样,以及如何“反击”它?

注意:我双击文件

谢谢!

代码示例:

def loader():
percentage = float(input("what percentage do you want?"))
x = 0
print("\nGoal:{} %".format(percentage))


if percentage <= 100 and percentage > 0:
    while x < percentage:
        x+=1
        print("Loading...{}%".format(x))

else:
    print ("Error, you can't overload/underload")


loader()

OR

def trinomial():

a = float(input("a?"))
b = float(input("b?"))
c = float(input("c?"))

print("\n a = {}\n b = {} \n c = {}".format(a,b,c))
print("So you are trying to find x for \n {}x^2 + ({}x) + ({})".format(a,b,c))

delta = b**2 - (4 * a * c)

if delta > 0:
    x1 = (-b - sqrt(delta))/(2*a)
    x2 = (-b + sqrt(delta))/(2*a)
    print("For x = {} or x = {}, the trinomial is solved".format(x1, x2))

elif delta < 0:
    print ("No values of x possible")

elif delta == 0: 
    #I know, I could have used "else"
    x1 = -b/(2*a)
    print("For x = {} the trinomial is solved".format(x1)) 

trinomial()

2 个答案:

答案 0 :(得分:1)

您提供的信息太少,但可能不是Python的问题,而是Windows控制台。从cmd应用程序打开程序,或等到按下Enter键。把它放在脚本的末尾。

sys.stdin.read(1)

答案 1 :(得分:1)

当你双击脚本时,它会启动一个新的 let playerScores = [ { player: 'Dealer', score: 19, cards: 'A of ♥, 5 of ♦' }, { player: 'Player1', score: 18, cards: '10 of ♦, 8 of ♦' }, { player: 'Player2', score: 23, cards: '6 of ♦, 6 of ♥, J of ♠' } ] console.log(playerScores) // iterates through playerScores for (let i in playerScores) { if (playerScores[i].score > 20) { console.log(playerScores[i].player + ' BUSTED!') // removes the object with a score over 21 from the array playerScores.splice(i,1) } return playerScores } 实例,打开一个绑定到该实例的终端窗口,通过它运行脚本(管道输出并监听该终端上的输入),然后在脚本结束时关闭终端和实例。

停止此操作的简单方法是从现有shell中调用脚本。使用python运行。

或者,您可以在代码末尾添加用户输入请求,例如:

python your_script_location