Description
KeyboardInterrupt is an error which occurs when a user interrupts a running program by pressing Ctrl+C. This error is specific for Python programs.
Reason of error
This error occurs when the user wants to terminate the program, but the program does not have the capability to terminate itself.
Example code
def main():
while True:
print("Hello World")
if __name__=="__main__":
main()
Solution to solve issue
To solve this issue, the program should be able to terminate itself. This can be done by using the try-except statement. This statement catches the KeyboardInterrupt error and allows the program to terminate itself.
Related Quiz:
RecursionError: maximum recursion depth exceeded, python
Wordpres plugin Advanced Quiz Post plugin
Building a Priority Queue in Java
ImportError: No module named 'module_name'
SystemError: unknown opcode, python
Implementing Bubble Sort Algorithm in Java
SyntaxError: invalid syntax python
ValueError: invalid literal for int() with base 10 , python