For the “q” (quit) option in my program menu, I have the following code:
elif choice == "q":
print()
That worked all right until I put it in an infinite loop, which kept printing blank lines. Is there a method that can quit the program? Else, can you think of another solution?
One way is to do:
You will have to
import sysof course.Another way is to
breakout of your infinite loop. For example, you could do this:Yet another way is to put your main loop in a function, and use
return:The only reason you need the
run()function when usingreturnis that (unlike some other languages) you can’t directlyreturnfrom the main part of your Python code (the part that’s not inside a function).