簡體   English   中英

Python程序將運行,但不會一直打開供我查看輸出

[英]Python program will run, but won't be kept open for me to look at the 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()

要么


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()

您提供的信息太少,但是可能不是Python問題,而是Windows控制台。 從cmd應用程序中打開程序,或者等待直到按下Enter鍵。 將其放在腳本的末尾。

sys.stdin.read(1)

當您雙擊腳本時,它將啟動一個新的python實例,打開一個綁定到該實例的終端窗口,通過腳本運行腳本(在終端上輸入輸出並偵聽輸入),然后關閉終端和實例腳本結束時。

停止此操作的簡單方法是從現有Shell中調用腳本。 使用python your_script_location運行。

或者,您可以在代碼末尾添加一個用戶輸入請求,例如:

# after all your other code, just before execution falls off the bottom...
input("Press enter to close...")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM