Does anyone know how to make python auto stop if you put something in?

This is my code.
grocery_list =["ham","carrots","apples","chips","bread","milk","candy"]
print("welcome to your virtaul grocery list!")
print("The first item on the list is ham")
print("Here's the list.")
question = input("Do you have ham? ")
if (question =='yes'):print("ok!")
elif (question == 'no'):print("cmon,get it! ok,NOW we can continue.")
else :
print("THE SYSTE<SM HAAAS>> NSOWE BE))(N BRO(^$#KEN.") right here I need to tell it to stop printing here if they say something other than yes or no.

You are viewing a single comment. View All

Easy. Just import the sys module at the top, and wherever you want to stop, just do sys.exit():


@OldWizard209 Thank you! I'll try that.


@SnowpawValdez Thanks! I removed "sys." and changed it to exit () and it's now working!