Issue
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?
Solution
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()
Answered By - chess_lover_6
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.