簡體   English   中英

Python文件可執行文件錯誤

[英]Python file executable error

我為使用python的游戲編寫了燃油計算器程序,然后使用cx_Freeze編譯為.exe。 它將其很好地轉換為.exe,我可以打開可執行文件,但是當腳本與用戶進行交互時,當用戶介紹所請求的信息時,按Enter鍵后窗口將關閉。 這是代碼的一部分,在向用戶請求了一些信息之后,程序進行了一些計算,但是我認為這是無關緊要的,因為問題出在輸入中。 我希望當用戶在請求的信息輸入中按Enter鍵時,程序不會關閉。

import sys

COMBUSTIBLE=chr(raw_input("Introduce unidad de combustible: "))
DURACION=chr(raw_input("Introduce unidad de duracion: "))

if COMBUSTIBLE != "litros" and COMBUSTIBLE != "kilos" and DURACION != "vueltas" and DURACION != "tiempo" and DURACION != "km":
    print "Error: Ambos argumentos son invalidos"
    print "Primer argumento debe ser 'litros' o 'kilos'"
    print "Segundo argumento debe ser 'tiempo' o 'vueltas' o 'km'"
    sys.exit(1)
elif COMBUSTIBLE != "litros" and COMBUSTIBLE != "kilos":
    print "Error: Primer argumento invalido"
    print "Primer argumento debe ser 'litros' o 'kilos'"
    sys.exit(2)
elif DURACION != "tiempo" and DURACION != "vueltas" and DURACION != "km":
    print "Error: Segundo argumento invalido"
    print "Segundo argumento debe ser 'tiempo' o 'vueltas' o 'km'"
    sys.exit(3)
else:
    pass

# TIPO 1 - LITROS - VUELTAS 
if COMBUSTIBLE == "l" and DURACION == "v":
    # DATA REQUEST
    RACE_DURATION=int(raw_input("Introduce el total de vueltas de la carrera: "))
    CAR_FUEL=float(raw_input("Introduce los litros totales del coche: "))
    FUEL_PER_LAP=float(raw_input("Introduce el consumo medio en litros por vuelta: "))

程序完成執行后,窗口將立即關閉。 因此,如果希望窗口保持打開狀態,則應刪除sys.exit()語句,並在腳本末尾添加一些內容,例如:

input("Press any key to exit: ") 

在Python 3或

raw_input("Press any key to exit: ") 

在Python 2中

暫無
暫無

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

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