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?

1
  • How are you running the program? Clicking it? Using the cmd prompt? Commented Sep 14, 2021 at 16:59

4 Answers 4

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() 
Sign up to request clarification or add additional context in comments.

1 Comment

Also you can launch the script via the command line and avoid having to add the input().
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') 

Comments

0

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.