Solution:
The given problem is solved in Python.
try:
n = int(input('Enter a number: '))
sq = n * n
print('Square of', n, 'is:', sq)
except KeyboardInterrupt:
print('Keyboard Interrupt Error generated.')
Explanation:
In Python, the KeyboardInterrupt error occurs when we try to run commands like CTRL + C while taking input from user.
This exception can be handled by using try-except block. Inside the try block, we will accept the input and display the square of the number. If keyboard interrupt occurs then it will be handled by the except block. An appropriate message is displayed on the screen in case of keyboard interrupt error.
Refer to the attachment for output.