How to Stop Python While Running?
I'm Going to the Programming Competition and I Need Help. How Do I Stop a Program While Code Is Running? I Tried the Sys. Exit () or Only Exit () but It...
I'm going to the programming competition and I need help. How do I stop a program while code is running? I tried the sys. exit () or only exit () but it doesn't work as I imagined. Here's the beginning of the code, so if anyone can help me, please answer. Thanks in future. Here is beginning of code: K = Int (input ()) J = Int (input ())
If K is < 9 or K, 11: Exit ()
If K is < 14 or K, 16: Exit ()
1 Answer
The code in your question has numerous errors, so let's start with Python code that prints the numbers between 1 and 10 at 5 second intervals between printing each number and then exits.
import time
i = 1
while True:
print(i)
i = i + 1
time.sleep(5)
if(i > 10):
break
The above code will take almost a minute to finish executing unless it is interrupted before it is finished. To exit from a program before it is finished press the key combination Ctrl + C
Results of pressing Ctrl + C:
^CTraceback (most recent call last):
File "print-1-to-10.py", line 6, in <module>
time.sleep(5)
KeyboardInterrupt
``