首页 > 解决方案 > 在 .py 文件完成运行之前关闭 Windows Python 3.7

问题描述

我在 Spyder 中编写了一个 python 脚本,并试图在我的机器上运行它,但 Windows 上的 Python 3.7 将它关闭得很早。

我的代码是:

print('Campus Pizza Ordering Program\n')

crust = input('What crust? Regular or Wheat? ') 
num_toppings = int(input('How many toppings (please enter a whole number)? '))
price = format((7 + num_toppings * 0.75),".2f") #looked up how to round to 2 decimals

print('\nYou have a '+crust+' pizza with '+str(num_toppings)+' toppings. ' +
      'The final price of the pizza is $'+str(price)+".")

该程序在执行最终打印语句之前关闭。为什么?

标签: pythonspyder

解决方案


考虑导入时间并time.sleep(5)在程序结束时使用,以便查看输出是否打印。


推荐阅读