0

I wrote a python script in Spyder and am trying to run it on my machine but Python 3.7 on windows closes it to early.

My code is:

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

The program closes though before the final print statement is executed. Why?

4 Answers4

1

I am assuming you are running this script through "run python file"(python terminal). This will close the window directly after you are done. The way to bypass this is by adding an empty input at the bottom.

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)+".")
input()
Random Davis
  • 6,662
  • 4
  • 14
  • 24
chess_lover_6
  • 632
  • 8
  • 22
0

Most likely what is happening here is that the program prints the final line then terminates immediately causing you to not see the print.

Try adding this to the end of your script:

input('\nPress "ENTER" to exit')
Rami M
  • 82
  • 5
0

Make sure that spyder is up to date because it can close if it is on an outdated version

Justin
  • 1
  • 2
0

Consider importing time and using time.sleep(5) at the end of your program so you can see if the output prints.